diff --git a/resource-manager/apimanagement/2024-05-01/allpolicies/README.md b/resource-manager/apimanagement/2024-05-01/allpolicies/README.md new file mode 100644 index 00000000000..9b9fe691039 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/allpolicies/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/allpolicies` Documentation + +The `allpolicies` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/allpolicies" +``` + + +### Client Initialization + +```go +client := allpolicies.NewAllPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AllPoliciesClient.ListByService` + +```go +ctx := context.TODO() +id := allpolicies.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id)` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/allpolicies/client.go b/resource-manager/apimanagement/2024-05-01/allpolicies/client.go new file mode 100644 index 00000000000..ddd718e8dde --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/allpolicies/client.go @@ -0,0 +1,26 @@ +package allpolicies + +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 AllPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewAllPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*AllPoliciesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "allpolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AllPoliciesClient: %+v", err) + } + + return &AllPoliciesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/allpolicies/constants.go b/resource-manager/apimanagement/2024-05-01/allpolicies/constants.go new file mode 100644 index 00000000000..a6e81873257 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/allpolicies/constants.go @@ -0,0 +1,54 @@ +package allpolicies + +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 PolicyComplianceState string + +const ( + PolicyComplianceStateCompliant PolicyComplianceState = "Compliant" + PolicyComplianceStateNonCompliant PolicyComplianceState = "NonCompliant" + PolicyComplianceStatePending PolicyComplianceState = "Pending" +) + +func PossibleValuesForPolicyComplianceState() []string { + return []string{ + string(PolicyComplianceStateCompliant), + string(PolicyComplianceStateNonCompliant), + string(PolicyComplianceStatePending), + } +} + +func (s *PolicyComplianceState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePolicyComplianceState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePolicyComplianceState(input string) (*PolicyComplianceState, error) { + vals := map[string]PolicyComplianceState{ + "compliant": PolicyComplianceStateCompliant, + "noncompliant": PolicyComplianceStateNonCompliant, + "pending": PolicyComplianceStatePending, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyComplianceState(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/allpolicies/id_service.go b/resource-manager/apimanagement/2024-05-01/allpolicies/id_service.go new file mode 100644 index 00000000000..28341dd0c33 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/allpolicies/id_service.go @@ -0,0 +1,130 @@ +package allpolicies + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/allpolicies/id_service_test.go b/resource-manager/apimanagement/2024-05-01/allpolicies/id_service_test.go new file mode 100644 index 00000000000..b0cb4c2ec78 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/allpolicies/id_service_test.go @@ -0,0 +1,282 @@ +package allpolicies + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/allpolicies/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/allpolicies/method_listbyservice.go new file mode 100644 index 00000000000..ccc173f14e7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/allpolicies/method_listbyservice.go @@ -0,0 +1,105 @@ +package allpolicies + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AllPoliciesContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []AllPoliciesContract +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c AllPoliciesClient) ListByService(ctx context.Context, id ServiceId) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/allPolicies", 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 *[]AllPoliciesContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c AllPoliciesClient) ListByServiceComplete(ctx context.Context, id ServiceId) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, AllPoliciesContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AllPoliciesClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, predicate AllPoliciesContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]AllPoliciesContract, 0) + + resp, err := c.ListByService(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/allpolicies/model_allpoliciescontract.go b/resource-manager/apimanagement/2024-05-01/allpolicies/model_allpoliciescontract.go new file mode 100644 index 00000000000..d0afa422345 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/allpolicies/model_allpoliciescontract.go @@ -0,0 +1,11 @@ +package allpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AllPoliciesContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AllPoliciesContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/allpolicies/model_allpoliciescontractproperties.go b/resource-manager/apimanagement/2024-05-01/allpolicies/model_allpoliciescontractproperties.go new file mode 100644 index 00000000000..eae092f1887 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/allpolicies/model_allpoliciescontractproperties.go @@ -0,0 +1,9 @@ +package allpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AllPoliciesContractProperties struct { + ComplianceState *PolicyComplianceState `json:"complianceState,omitempty"` + ReferencePolicyId *string `json:"referencePolicyId,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/allpolicies/predicates.go b/resource-manager/apimanagement/2024-05-01/allpolicies/predicates.go new file mode 100644 index 00000000000..90c589e21ca --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/allpolicies/predicates.go @@ -0,0 +1,27 @@ +package allpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AllPoliciesContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AllPoliciesContractOperationPredicate) Matches(input AllPoliciesContract) 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/apimanagement/2024-05-01/allpolicies/version.go b/resource-manager/apimanagement/2024-05-01/allpolicies/version.go new file mode 100644 index 00000000000..cc456cdda84 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/allpolicies/version.go @@ -0,0 +1,12 @@ +package allpolicies + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/allpolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/api/README.md b/resource-manager/apimanagement/2024-05-01/api/README.md new file mode 100644 index 00000000000..9982403d633 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/README.md @@ -0,0 +1,222 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/api` Documentation + +The `api` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/api" +``` + + +### Client Initialization + +```go +client := api.NewApiClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := api.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +payload := api.ApiCreateOrUpdateParameter{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload, api.DefaultCreateOrUpdateOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `ApiClient.Delete` + +```go +ctx := context.TODO() +id := api.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +if err := client.DeleteThenPoll(ctx, id, api.DefaultDeleteOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `ApiClient.Get` + +```go +ctx := context.TODO() +id := api.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +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: `ApiClient.GetEntityTag` + +```go +ctx := context.TODO() +id := api.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiClient.ListByService` + +```go +ctx := context.TODO() +id := api.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, api.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, api.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ApiClient.Update` + +```go +ctx := context.TODO() +id := api.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +payload := api.ApiUpdateContract{ + // ... +} + + +read, err := client.Update(ctx, id, payload, api.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiClient.WorkspaceApiCreateOrUpdate` + +```go +ctx := context.TODO() +id := api.NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue") + +payload := api.ApiCreateOrUpdateParameter{ + // ... +} + + +if err := client.WorkspaceApiCreateOrUpdateThenPoll(ctx, id, payload, api.DefaultWorkspaceApiCreateOrUpdateOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `ApiClient.WorkspaceApiDelete` + +```go +ctx := context.TODO() +id := api.NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue") + +read, err := client.WorkspaceApiDelete(ctx, id, api.DefaultWorkspaceApiDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiClient.WorkspaceApiGet` + +```go +ctx := context.TODO() +id := api.NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue") + +read, err := client.WorkspaceApiGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiClient.WorkspaceApiGetEntityTag` + +```go +ctx := context.TODO() +id := api.NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue") + +read, err := client.WorkspaceApiGetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiClient.WorkspaceApiListByService` + +```go +ctx := context.TODO() +id := api.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +// alternatively `client.WorkspaceApiListByService(ctx, id, api.DefaultWorkspaceApiListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.WorkspaceApiListByServiceComplete(ctx, id, api.DefaultWorkspaceApiListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ApiClient.WorkspaceApiUpdate` + +```go +ctx := context.TODO() +id := api.NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue") + +payload := api.ApiUpdateContract{ + // ... +} + + +read, err := client.WorkspaceApiUpdate(ctx, id, payload, api.DefaultWorkspaceApiUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/api/client.go b/resource-manager/apimanagement/2024-05-01/api/client.go new file mode 100644 index 00000000000..5ce28196132 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/client.go @@ -0,0 +1,26 @@ +package api + +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 ApiClient struct { + Client *resourcemanager.Client +} + +func NewApiClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "api", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiClient: %+v", err) + } + + return &ApiClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/api/constants.go b/resource-manager/apimanagement/2024-05-01/api/constants.go new file mode 100644 index 00000000000..4ff3628955f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/constants.go @@ -0,0 +1,369 @@ +package api + +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 ApiType string + +const ( + ApiTypeGraphql ApiType = "graphql" + ApiTypeGrpc ApiType = "grpc" + ApiTypeHTTP ApiType = "http" + ApiTypeOdata ApiType = "odata" + ApiTypeSoap ApiType = "soap" + ApiTypeWebsocket ApiType = "websocket" +) + +func PossibleValuesForApiType() []string { + return []string{ + string(ApiTypeGraphql), + string(ApiTypeGrpc), + string(ApiTypeHTTP), + string(ApiTypeOdata), + string(ApiTypeSoap), + string(ApiTypeWebsocket), + } +} + +func (s *ApiType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseApiType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseApiType(input string) (*ApiType, error) { + vals := map[string]ApiType{ + "graphql": ApiTypeGraphql, + "grpc": ApiTypeGrpc, + "http": ApiTypeHTTP, + "odata": ApiTypeOdata, + "soap": ApiTypeSoap, + "websocket": ApiTypeWebsocket, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ApiType(input) + return &out, nil +} + +type BearerTokenSendingMethods string + +const ( + BearerTokenSendingMethodsAuthorizationHeader BearerTokenSendingMethods = "authorizationHeader" + BearerTokenSendingMethodsQuery BearerTokenSendingMethods = "query" +) + +func PossibleValuesForBearerTokenSendingMethods() []string { + return []string{ + string(BearerTokenSendingMethodsAuthorizationHeader), + string(BearerTokenSendingMethodsQuery), + } +} + +func (s *BearerTokenSendingMethods) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBearerTokenSendingMethods(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBearerTokenSendingMethods(input string) (*BearerTokenSendingMethods, error) { + vals := map[string]BearerTokenSendingMethods{ + "authorizationheader": BearerTokenSendingMethodsAuthorizationHeader, + "query": BearerTokenSendingMethodsQuery, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BearerTokenSendingMethods(input) + return &out, nil +} + +type ContentFormat string + +const ( + ContentFormatGraphqlNegativelink ContentFormat = "graphql-link" + ContentFormatGrpc ContentFormat = "grpc" + ContentFormatGrpcNegativelink ContentFormat = "grpc-link" + ContentFormatOdata ContentFormat = "odata" + ContentFormatOdataNegativelink ContentFormat = "odata-link" + ContentFormatOpenapi ContentFormat = "openapi" + ContentFormatOpenapiNegativelink ContentFormat = "openapi-link" + ContentFormatOpenapiPositivejson ContentFormat = "openapi+json" + ContentFormatOpenapiPositivejsonNegativelink ContentFormat = "openapi+json-link" + ContentFormatSwaggerNegativejson ContentFormat = "swagger-json" + ContentFormatSwaggerNegativelinkNegativejson ContentFormat = "swagger-link-json" + ContentFormatWadlNegativelinkNegativejson ContentFormat = "wadl-link-json" + ContentFormatWadlNegativexml ContentFormat = "wadl-xml" + ContentFormatWsdl ContentFormat = "wsdl" + ContentFormatWsdlNegativelink ContentFormat = "wsdl-link" +) + +func PossibleValuesForContentFormat() []string { + return []string{ + string(ContentFormatGraphqlNegativelink), + string(ContentFormatGrpc), + string(ContentFormatGrpcNegativelink), + string(ContentFormatOdata), + string(ContentFormatOdataNegativelink), + string(ContentFormatOpenapi), + string(ContentFormatOpenapiNegativelink), + string(ContentFormatOpenapiPositivejson), + string(ContentFormatOpenapiPositivejsonNegativelink), + string(ContentFormatSwaggerNegativejson), + string(ContentFormatSwaggerNegativelinkNegativejson), + string(ContentFormatWadlNegativelinkNegativejson), + string(ContentFormatWadlNegativexml), + string(ContentFormatWsdl), + string(ContentFormatWsdlNegativelink), + } +} + +func (s *ContentFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseContentFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseContentFormat(input string) (*ContentFormat, error) { + vals := map[string]ContentFormat{ + "graphql-link": ContentFormatGraphqlNegativelink, + "grpc": ContentFormatGrpc, + "grpc-link": ContentFormatGrpcNegativelink, + "odata": ContentFormatOdata, + "odata-link": ContentFormatOdataNegativelink, + "openapi": ContentFormatOpenapi, + "openapi-link": ContentFormatOpenapiNegativelink, + "openapi+json": ContentFormatOpenapiPositivejson, + "openapi+json-link": ContentFormatOpenapiPositivejsonNegativelink, + "swagger-json": ContentFormatSwaggerNegativejson, + "swagger-link-json": ContentFormatSwaggerNegativelinkNegativejson, + "wadl-link-json": ContentFormatWadlNegativelinkNegativejson, + "wadl-xml": ContentFormatWadlNegativexml, + "wsdl": ContentFormatWsdl, + "wsdl-link": ContentFormatWsdlNegativelink, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ContentFormat(input) + return &out, nil +} + +type Protocol string + +const ( + ProtocolHTTP Protocol = "http" + ProtocolHTTPS Protocol = "https" + ProtocolWs Protocol = "ws" + ProtocolWss Protocol = "wss" +) + +func PossibleValuesForProtocol() []string { + return []string{ + string(ProtocolHTTP), + string(ProtocolHTTPS), + string(ProtocolWs), + string(ProtocolWss), + } +} + +func (s *Protocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProtocol(input string) (*Protocol, error) { + vals := map[string]Protocol{ + "http": ProtocolHTTP, + "https": ProtocolHTTPS, + "ws": ProtocolWs, + "wss": ProtocolWss, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Protocol(input) + return &out, nil +} + +type SoapApiType string + +const ( + SoapApiTypeGraphql SoapApiType = "graphql" + SoapApiTypeGrpc SoapApiType = "grpc" + SoapApiTypeHTTP SoapApiType = "http" + SoapApiTypeOdata SoapApiType = "odata" + SoapApiTypeSoap SoapApiType = "soap" + SoapApiTypeWebsocket SoapApiType = "websocket" +) + +func PossibleValuesForSoapApiType() []string { + return []string{ + string(SoapApiTypeGraphql), + string(SoapApiTypeGrpc), + string(SoapApiTypeHTTP), + string(SoapApiTypeOdata), + string(SoapApiTypeSoap), + string(SoapApiTypeWebsocket), + } +} + +func (s *SoapApiType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSoapApiType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSoapApiType(input string) (*SoapApiType, error) { + vals := map[string]SoapApiType{ + "graphql": SoapApiTypeGraphql, + "grpc": SoapApiTypeGrpc, + "http": SoapApiTypeHTTP, + "odata": SoapApiTypeOdata, + "soap": SoapApiTypeSoap, + "websocket": SoapApiTypeWebsocket, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SoapApiType(input) + return &out, nil +} + +type TranslateRequiredQueryParametersConduct string + +const ( + TranslateRequiredQueryParametersConductQuery TranslateRequiredQueryParametersConduct = "query" + TranslateRequiredQueryParametersConductTemplate TranslateRequiredQueryParametersConduct = "template" +) + +func PossibleValuesForTranslateRequiredQueryParametersConduct() []string { + return []string{ + string(TranslateRequiredQueryParametersConductQuery), + string(TranslateRequiredQueryParametersConductTemplate), + } +} + +func (s *TranslateRequiredQueryParametersConduct) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTranslateRequiredQueryParametersConduct(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTranslateRequiredQueryParametersConduct(input string) (*TranslateRequiredQueryParametersConduct, error) { + vals := map[string]TranslateRequiredQueryParametersConduct{ + "query": TranslateRequiredQueryParametersConductQuery, + "template": TranslateRequiredQueryParametersConductTemplate, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TranslateRequiredQueryParametersConduct(input) + return &out, nil +} + +type VersioningScheme string + +const ( + VersioningSchemeHeader VersioningScheme = "Header" + VersioningSchemeQuery VersioningScheme = "Query" + VersioningSchemeSegment VersioningScheme = "Segment" +) + +func PossibleValuesForVersioningScheme() []string { + return []string{ + string(VersioningSchemeHeader), + string(VersioningSchemeQuery), + string(VersioningSchemeSegment), + } +} + +func (s *VersioningScheme) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVersioningScheme(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVersioningScheme(input string) (*VersioningScheme, error) { + vals := map[string]VersioningScheme{ + "header": VersioningSchemeHeader, + "query": VersioningSchemeQuery, + "segment": VersioningSchemeSegment, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VersioningScheme(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/api/id_api.go b/resource-manager/apimanagement/2024-05-01/api/id_api.go new file mode 100644 index 00000000000..a70d7f5620c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/id_api.go @@ -0,0 +1,139 @@ +package api + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiId{}) +} + +var _ resourceids.ResourceId = &ApiId{} + +// ApiId is a struct representing the Resource ID for a Api +type ApiId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string +} + +// NewApiID returns a new ApiId struct +func NewApiID(subscriptionId string, resourceGroupName string, serviceName string, apiId string) ApiId { + return ApiId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + } +} + +// ParseApiID parses 'input' into a ApiId +func ParseApiID(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiIDInsensitively parses 'input' case-insensitively into a ApiId +// note: this method should only be used for API response data and not user input +func ParseApiIDInsensitively(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + return nil +} + +// ValidateApiID checks that 'input' can be parsed as a Api ID +func ValidateApiID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api ID +func (id ApiId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api ID +func (id ApiId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + } +} + +// String returns a human-readable description of this Api ID +func (id ApiId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + } + return fmt.Sprintf("Api (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/api/id_api_test.go b/resource-manager/apimanagement/2024-05-01/api/id_api_test.go new file mode 100644 index 00000000000..8e807ddb657 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/id_api_test.go @@ -0,0 +1,327 @@ +package api + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiId{} + +func TestNewApiID(t *testing.T) { + id := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } +} + +func TestFormatApiID(t *testing.T) { + actual := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestParseApiIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestSegmentsForApiId(t *testing.T) { + segments := ApiId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/api/id_service.go b/resource-manager/apimanagement/2024-05-01/api/id_service.go new file mode 100644 index 00000000000..c50464ed710 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/id_service.go @@ -0,0 +1,130 @@ +package api + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/api/id_service_test.go b/resource-manager/apimanagement/2024-05-01/api/id_service_test.go new file mode 100644 index 00000000000..13b07775adb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/id_service_test.go @@ -0,0 +1,282 @@ +package api + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/api/id_workspace.go b/resource-manager/apimanagement/2024-05-01/api/id_workspace.go new file mode 100644 index 00000000000..33d92e28640 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/id_workspace.go @@ -0,0 +1,139 @@ +package api + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/api/id_workspace_test.go b/resource-manager/apimanagement/2024-05-01/api/id_workspace_test.go new file mode 100644 index 00000000000..84ba64fafd7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/id_workspace_test.go @@ -0,0 +1,327 @@ +package api + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/api/id_workspaceapi.go b/resource-manager/apimanagement/2024-05-01/api/id_workspaceapi.go new file mode 100644 index 00000000000..5d2d28b9caf --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/id_workspaceapi.go @@ -0,0 +1,148 @@ +package api + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceApiId{}) +} + +var _ resourceids.ResourceId = &WorkspaceApiId{} + +// WorkspaceApiId is a struct representing the Resource ID for a Workspace Api +type WorkspaceApiId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + ApiId string +} + +// NewWorkspaceApiID returns a new WorkspaceApiId struct +func NewWorkspaceApiID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, apiId string) WorkspaceApiId { + return WorkspaceApiId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + ApiId: apiId, + } +} + +// ParseWorkspaceApiID parses 'input' into a WorkspaceApiId +func ParseWorkspaceApiID(input string) (*WorkspaceApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceApiId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceApiIDInsensitively parses 'input' case-insensitively into a WorkspaceApiId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceApiIDInsensitively(input string) (*WorkspaceApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceApiId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceApiId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + return nil +} + +// ValidateWorkspaceApiID checks that 'input' can be parsed as a Workspace Api ID +func ValidateWorkspaceApiID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceApiID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Api ID +func (id WorkspaceApiId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/apis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.ApiId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Api ID +func (id WorkspaceApiId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + } +} + +// String returns a human-readable description of this Workspace Api ID +func (id WorkspaceApiId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Api: %q", id.ApiId), + } + return fmt.Sprintf("Workspace Api (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/api/id_workspaceapi_test.go b/resource-manager/apimanagement/2024-05-01/api/id_workspaceapi_test.go new file mode 100644 index 00000000000..745e7153e56 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/id_workspaceapi_test.go @@ -0,0 +1,372 @@ +package api + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceApiId{} + +func TestNewWorkspaceApiID(t *testing.T) { + id := NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } +} + +func TestFormatWorkspaceApiID(t *testing.T) { + actual := NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceApiID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue", + Expected: &WorkspaceApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceApiID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestParseWorkspaceApiIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue", + Expected: &WorkspaceApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE", + Expected: &WorkspaceApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + ApiId: "aPiIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceApiIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestSegmentsForWorkspaceApiId(t *testing.T) { + segments := WorkspaceApiId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceApiId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/api/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/api/method_createorupdate.go new file mode 100644 index 00000000000..b95d5839846 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/method_createorupdate.go @@ -0,0 +1,103 @@ +package api + +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 *ApiContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c ApiClient) CreateOrUpdate(ctx context.Context, id ApiId, input ApiCreateOrUpdateParameter, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 ApiClient) CreateOrUpdateThenPoll(ctx context.Context, id ApiId, input ApiCreateOrUpdateParameter, options CreateOrUpdateOperationOptions) error { + result, err := c.CreateOrUpdate(ctx, id, input, options) + 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/apimanagement/2024-05-01/api/method_delete.go b/resource-manager/apimanagement/2024-05-01/api/method_delete.go new file mode 100644 index 00000000000..d4625ea7e66 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/method_delete.go @@ -0,0 +1,101 @@ +package api + +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 +} + +type DeleteOperationOptions struct { + DeleteRevisions *bool + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.DeleteRevisions != nil { + out.Append("deleteRevisions", fmt.Sprintf("%v", *o.DeleteRevisions)) + } + return &out +} + +// Delete ... +func (c ApiClient) Delete(ctx context.Context, id ApiId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + 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 ApiClient) DeleteThenPoll(ctx context.Context, id ApiId, options DeleteOperationOptions) error { + result, err := c.Delete(ctx, id, options) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/apimanagement/2024-05-01/api/method_get.go b/resource-manager/apimanagement/2024-05-01/api/method_get.go new file mode 100644 index 00000000000..07f671ef642 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/method_get.go @@ -0,0 +1,54 @@ +package api + +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 *ApiContract +} + +// Get ... +func (c ApiClient) Get(ctx context.Context, id ApiId) (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 ApiContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/api/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/api/method_getentitytag.go new file mode 100644 index 00000000000..5d65ab7fc88 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/method_getentitytag.go @@ -0,0 +1,46 @@ +package api + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c ApiClient) GetEntityTag(ctx context.Context, id ApiId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/api/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/api/method_listbyservice.go new file mode 100644 index 00000000000..6b9bc61fa02 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/method_listbyservice.go @@ -0,0 +1,149 @@ +package api + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ApiContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ApiContract +} + +type ListByServiceOperationOptions struct { + ExpandApiVersionSet *bool + Filter *string + Skip *int64 + Tags *string + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.ExpandApiVersionSet != nil { + out.Append("expandApiVersionSet", fmt.Sprintf("%v", *o.ExpandApiVersionSet)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Tags != nil { + out.Append("tags", fmt.Sprintf("%v", *o.Tags)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c ApiClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/apis", 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 *[]ApiContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c ApiClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, ApiContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate ApiContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]ApiContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/api/method_update.go b/resource-manager/apimanagement/2024-05-01/api/method_update.go new file mode 100644 index 00000000000..491fbbeb5c8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/method_update.go @@ -0,0 +1,87 @@ +package api + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ApiContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c ApiClient) Update(ctx context.Context, id ApiId, input ApiUpdateContract, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 ApiContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/api/method_workspaceapicreateorupdate.go b/resource-manager/apimanagement/2024-05-01/api/method_workspaceapicreateorupdate.go new file mode 100644 index 00000000000..c7a255c688a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/method_workspaceapicreateorupdate.go @@ -0,0 +1,103 @@ +package api + +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 WorkspaceApiCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ApiContract +} + +type WorkspaceApiCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceApiCreateOrUpdateOperationOptions() WorkspaceApiCreateOrUpdateOperationOptions { + return WorkspaceApiCreateOrUpdateOperationOptions{} +} + +func (o WorkspaceApiCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceApiCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceApiCreateOrUpdate ... +func (c ApiClient) WorkspaceApiCreateOrUpdate(ctx context.Context, id WorkspaceApiId, input ApiCreateOrUpdateParameter, options WorkspaceApiCreateOrUpdateOperationOptions) (result WorkspaceApiCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 +} + +// WorkspaceApiCreateOrUpdateThenPoll performs WorkspaceApiCreateOrUpdate then polls until it's completed +func (c ApiClient) WorkspaceApiCreateOrUpdateThenPoll(ctx context.Context, id WorkspaceApiId, input ApiCreateOrUpdateParameter, options WorkspaceApiCreateOrUpdateOperationOptions) error { + result, err := c.WorkspaceApiCreateOrUpdate(ctx, id, input, options) + if err != nil { + return fmt.Errorf("performing WorkspaceApiCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after WorkspaceApiCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/apimanagement/2024-05-01/api/method_workspaceapidelete.go b/resource-manager/apimanagement/2024-05-01/api/method_workspaceapidelete.go new file mode 100644 index 00000000000..44393545209 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/method_workspaceapidelete.go @@ -0,0 +1,79 @@ +package api + +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 WorkspaceApiDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type WorkspaceApiDeleteOperationOptions struct { + DeleteRevisions *bool + IfMatch *string +} + +func DefaultWorkspaceApiDeleteOperationOptions() WorkspaceApiDeleteOperationOptions { + return WorkspaceApiDeleteOperationOptions{} +} + +func (o WorkspaceApiDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceApiDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.DeleteRevisions != nil { + out.Append("deleteRevisions", fmt.Sprintf("%v", *o.DeleteRevisions)) + } + return &out +} + +// WorkspaceApiDelete ... +func (c ApiClient) WorkspaceApiDelete(ctx context.Context, id WorkspaceApiId, options WorkspaceApiDeleteOperationOptions) (result WorkspaceApiDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/api/method_workspaceapiget.go b/resource-manager/apimanagement/2024-05-01/api/method_workspaceapiget.go new file mode 100644 index 00000000000..220b742d573 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/method_workspaceapiget.go @@ -0,0 +1,54 @@ +package api + +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 WorkspaceApiGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ApiContract +} + +// WorkspaceApiGet ... +func (c ApiClient) WorkspaceApiGet(ctx context.Context, id WorkspaceApiId) (result WorkspaceApiGetOperationResponse, 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 ApiContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/api/method_workspaceapigetentitytag.go b/resource-manager/apimanagement/2024-05-01/api/method_workspaceapigetentitytag.go new file mode 100644 index 00000000000..dc7682fdf4e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/method_workspaceapigetentitytag.go @@ -0,0 +1,46 @@ +package api + +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 WorkspaceApiGetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceApiGetEntityTag ... +func (c ApiClient) WorkspaceApiGetEntityTag(ctx context.Context, id WorkspaceApiId) (result WorkspaceApiGetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/api/method_workspaceapilistbyservice.go b/resource-manager/apimanagement/2024-05-01/api/method_workspaceapilistbyservice.go new file mode 100644 index 00000000000..aeed0e70077 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/method_workspaceapilistbyservice.go @@ -0,0 +1,149 @@ +package api + +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 WorkspaceApiListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ApiContract +} + +type WorkspaceApiListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ApiContract +} + +type WorkspaceApiListByServiceOperationOptions struct { + ExpandApiVersionSet *bool + Filter *string + Skip *int64 + Tags *string + Top *int64 +} + +func DefaultWorkspaceApiListByServiceOperationOptions() WorkspaceApiListByServiceOperationOptions { + return WorkspaceApiListByServiceOperationOptions{} +} + +func (o WorkspaceApiListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceApiListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.ExpandApiVersionSet != nil { + out.Append("expandApiVersionSet", fmt.Sprintf("%v", *o.ExpandApiVersionSet)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Tags != nil { + out.Append("tags", fmt.Sprintf("%v", *o.Tags)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspaceApiListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceApiListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceApiListByService ... +func (c ApiClient) WorkspaceApiListByService(ctx context.Context, id WorkspaceId, options WorkspaceApiListByServiceOperationOptions) (result WorkspaceApiListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspaceApiListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/apis", 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 *[]ApiContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceApiListByServiceComplete retrieves all the results into a single object +func (c ApiClient) WorkspaceApiListByServiceComplete(ctx context.Context, id WorkspaceId, options WorkspaceApiListByServiceOperationOptions) (WorkspaceApiListByServiceCompleteResult, error) { + return c.WorkspaceApiListByServiceCompleteMatchingPredicate(ctx, id, options, ApiContractOperationPredicate{}) +} + +// WorkspaceApiListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiClient) WorkspaceApiListByServiceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options WorkspaceApiListByServiceOperationOptions, predicate ApiContractOperationPredicate) (result WorkspaceApiListByServiceCompleteResult, err error) { + items := make([]ApiContract, 0) + + resp, err := c.WorkspaceApiListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceApiListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/api/method_workspaceapiupdate.go b/resource-manager/apimanagement/2024-05-01/api/method_workspaceapiupdate.go new file mode 100644 index 00000000000..25f72466ee3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/method_workspaceapiupdate.go @@ -0,0 +1,87 @@ +package api + +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 WorkspaceApiUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ApiContract +} + +type WorkspaceApiUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceApiUpdateOperationOptions() WorkspaceApiUpdateOperationOptions { + return WorkspaceApiUpdateOperationOptions{} +} + +func (o WorkspaceApiUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceApiUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceApiUpdate ... +func (c ApiClient) WorkspaceApiUpdate(ctx context.Context, id WorkspaceApiId, input ApiUpdateContract, options WorkspaceApiUpdateOperationOptions) (result WorkspaceApiUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 ApiContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/api/model_apicontactinformation.go b/resource-manager/apimanagement/2024-05-01/api/model_apicontactinformation.go new file mode 100644 index 00000000000..18f05550be7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/model_apicontactinformation.go @@ -0,0 +1,10 @@ +package api + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiContactInformation struct { + Email *string `json:"email,omitempty"` + Name *string `json:"name,omitempty"` + Url *string `json:"url,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/api/model_apicontract.go b/resource-manager/apimanagement/2024-05-01/api/model_apicontract.go new file mode 100644 index 00000000000..27bc06fcbfc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/model_apicontract.go @@ -0,0 +1,11 @@ +package api + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ApiContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/api/model_apicontractproperties.go b/resource-manager/apimanagement/2024-05-01/api/model_apicontractproperties.go new file mode 100644 index 00000000000..50984f3b2cb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/model_apicontractproperties.go @@ -0,0 +1,29 @@ +package api + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiContractProperties struct { + ApiRevision *string `json:"apiRevision,omitempty"` + ApiRevisionDescription *string `json:"apiRevisionDescription,omitempty"` + ApiVersion *string `json:"apiVersion,omitempty"` + ApiVersionDescription *string `json:"apiVersionDescription,omitempty"` + ApiVersionSet *ApiVersionSetContractDetails `json:"apiVersionSet,omitempty"` + ApiVersionSetId *string `json:"apiVersionSetId,omitempty"` + AuthenticationSettings *AuthenticationSettingsContract `json:"authenticationSettings,omitempty"` + Contact *ApiContactInformation `json:"contact,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + IsCurrent *bool `json:"isCurrent,omitempty"` + IsOnline *bool `json:"isOnline,omitempty"` + License *ApiLicenseInformation `json:"license,omitempty"` + Path string `json:"path"` + Protocols *[]Protocol `json:"protocols,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + ServiceUrl *string `json:"serviceUrl,omitempty"` + SourceApiId *string `json:"sourceApiId,omitempty"` + SubscriptionKeyParameterNames *SubscriptionKeyParameterNamesContract `json:"subscriptionKeyParameterNames,omitempty"` + SubscriptionRequired *bool `json:"subscriptionRequired,omitempty"` + TermsOfServiceUrl *string `json:"termsOfServiceUrl,omitempty"` + Type *ApiType `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/api/model_apicontractupdateproperties.go b/resource-manager/apimanagement/2024-05-01/api/model_apicontractupdateproperties.go new file mode 100644 index 00000000000..fe0189ae882 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/model_apicontractupdateproperties.go @@ -0,0 +1,26 @@ +package api + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiContractUpdateProperties struct { + ApiRevision *string `json:"apiRevision,omitempty"` + ApiRevisionDescription *string `json:"apiRevisionDescription,omitempty"` + ApiVersion *string `json:"apiVersion,omitempty"` + ApiVersionDescription *string `json:"apiVersionDescription,omitempty"` + ApiVersionSetId *string `json:"apiVersionSetId,omitempty"` + AuthenticationSettings *AuthenticationSettingsContract `json:"authenticationSettings,omitempty"` + Contact *ApiContactInformation `json:"contact,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + IsCurrent *bool `json:"isCurrent,omitempty"` + IsOnline *bool `json:"isOnline,omitempty"` + License *ApiLicenseInformation `json:"license,omitempty"` + Path *string `json:"path,omitempty"` + Protocols *[]Protocol `json:"protocols,omitempty"` + ServiceUrl *string `json:"serviceUrl,omitempty"` + SubscriptionKeyParameterNames *SubscriptionKeyParameterNamesContract `json:"subscriptionKeyParameterNames,omitempty"` + SubscriptionRequired *bool `json:"subscriptionRequired,omitempty"` + TermsOfServiceUrl *string `json:"termsOfServiceUrl,omitempty"` + Type *ApiType `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/api/model_apicreateorupdateparameter.go b/resource-manager/apimanagement/2024-05-01/api/model_apicreateorupdateparameter.go new file mode 100644 index 00000000000..827cef00b3d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/model_apicreateorupdateparameter.go @@ -0,0 +1,8 @@ +package api + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiCreateOrUpdateParameter struct { + Properties *ApiCreateOrUpdateProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/api/model_apicreateorupdateproperties.go b/resource-manager/apimanagement/2024-05-01/api/model_apicreateorupdateproperties.go new file mode 100644 index 00000000000..000abe8abbd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/model_apicreateorupdateproperties.go @@ -0,0 +1,34 @@ +package api + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiCreateOrUpdateProperties struct { + ApiRevision *string `json:"apiRevision,omitempty"` + ApiRevisionDescription *string `json:"apiRevisionDescription,omitempty"` + ApiType *SoapApiType `json:"apiType,omitempty"` + ApiVersion *string `json:"apiVersion,omitempty"` + ApiVersionDescription *string `json:"apiVersionDescription,omitempty"` + ApiVersionSet *ApiVersionSetContractDetails `json:"apiVersionSet,omitempty"` + ApiVersionSetId *string `json:"apiVersionSetId,omitempty"` + AuthenticationSettings *AuthenticationSettingsContract `json:"authenticationSettings,omitempty"` + Contact *ApiContactInformation `json:"contact,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + Format *ContentFormat `json:"format,omitempty"` + IsCurrent *bool `json:"isCurrent,omitempty"` + IsOnline *bool `json:"isOnline,omitempty"` + License *ApiLicenseInformation `json:"license,omitempty"` + Path string `json:"path"` + Protocols *[]Protocol `json:"protocols,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + ServiceUrl *string `json:"serviceUrl,omitempty"` + SourceApiId *string `json:"sourceApiId,omitempty"` + SubscriptionKeyParameterNames *SubscriptionKeyParameterNamesContract `json:"subscriptionKeyParameterNames,omitempty"` + SubscriptionRequired *bool `json:"subscriptionRequired,omitempty"` + TermsOfServiceUrl *string `json:"termsOfServiceUrl,omitempty"` + TranslateRequiredQueryParameters *TranslateRequiredQueryParametersConduct `json:"translateRequiredQueryParameters,omitempty"` + Type *ApiType `json:"type,omitempty"` + Value *string `json:"value,omitempty"` + WsdlSelector *ApiCreateOrUpdatePropertiesWsdlSelector `json:"wsdlSelector,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/api/model_apicreateorupdatepropertieswsdlselector.go b/resource-manager/apimanagement/2024-05-01/api/model_apicreateorupdatepropertieswsdlselector.go new file mode 100644 index 00000000000..bf784d03705 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/model_apicreateorupdatepropertieswsdlselector.go @@ -0,0 +1,9 @@ +package api + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiCreateOrUpdatePropertiesWsdlSelector struct { + WsdlEndpointName *string `json:"wsdlEndpointName,omitempty"` + WsdlServiceName *string `json:"wsdlServiceName,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/api/model_apilicenseinformation.go b/resource-manager/apimanagement/2024-05-01/api/model_apilicenseinformation.go new file mode 100644 index 00000000000..73fa0cfd9a9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/model_apilicenseinformation.go @@ -0,0 +1,9 @@ +package api + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiLicenseInformation struct { + Name *string `json:"name,omitempty"` + Url *string `json:"url,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/api/model_apiupdatecontract.go b/resource-manager/apimanagement/2024-05-01/api/model_apiupdatecontract.go new file mode 100644 index 00000000000..a6d5dabf58a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/model_apiupdatecontract.go @@ -0,0 +1,8 @@ +package api + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiUpdateContract struct { + Properties *ApiContractUpdateProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/api/model_apiversionsetcontractdetails.go b/resource-manager/apimanagement/2024-05-01/api/model_apiversionsetcontractdetails.go new file mode 100644 index 00000000000..35b7f1f5294 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/model_apiversionsetcontractdetails.go @@ -0,0 +1,13 @@ +package api + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiVersionSetContractDetails struct { + Description *string `json:"description,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + VersionHeaderName *string `json:"versionHeaderName,omitempty"` + VersionQueryName *string `json:"versionQueryName,omitempty"` + VersioningScheme *VersioningScheme `json:"versioningScheme,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/api/model_authenticationsettingscontract.go b/resource-manager/apimanagement/2024-05-01/api/model_authenticationsettingscontract.go new file mode 100644 index 00000000000..1de3a61fc02 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/model_authenticationsettingscontract.go @@ -0,0 +1,11 @@ +package api + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthenticationSettingsContract struct { + OAuth2 *OAuth2AuthenticationSettingsContract `json:"oAuth2,omitempty"` + OAuth2AuthenticationSettings *[]OAuth2AuthenticationSettingsContract `json:"oAuth2AuthenticationSettings,omitempty"` + Openid *OpenIdAuthenticationSettingsContract `json:"openid,omitempty"` + OpenidAuthenticationSettings *[]OpenIdAuthenticationSettingsContract `json:"openidAuthenticationSettings,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/api/model_oauth2authenticationsettingscontract.go b/resource-manager/apimanagement/2024-05-01/api/model_oauth2authenticationsettingscontract.go new file mode 100644 index 00000000000..9aa0dda0317 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/model_oauth2authenticationsettingscontract.go @@ -0,0 +1,9 @@ +package api + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OAuth2AuthenticationSettingsContract struct { + AuthorizationServerId *string `json:"authorizationServerId,omitempty"` + Scope *string `json:"scope,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/api/model_openidauthenticationsettingscontract.go b/resource-manager/apimanagement/2024-05-01/api/model_openidauthenticationsettingscontract.go new file mode 100644 index 00000000000..2cd5f005f83 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/model_openidauthenticationsettingscontract.go @@ -0,0 +1,9 @@ +package api + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OpenIdAuthenticationSettingsContract struct { + BearerTokenSendingMethods *[]BearerTokenSendingMethods `json:"bearerTokenSendingMethods,omitempty"` + OpenidProviderId *string `json:"openidProviderId,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/api/model_subscriptionkeyparameternamescontract.go b/resource-manager/apimanagement/2024-05-01/api/model_subscriptionkeyparameternamescontract.go new file mode 100644 index 00000000000..f8315aaa868 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/model_subscriptionkeyparameternamescontract.go @@ -0,0 +1,9 @@ +package api + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionKeyParameterNamesContract struct { + Header *string `json:"header,omitempty"` + Query *string `json:"query,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/api/predicates.go b/resource-manager/apimanagement/2024-05-01/api/predicates.go new file mode 100644 index 00000000000..780e16ccd7f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/predicates.go @@ -0,0 +1,27 @@ +package api + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ApiContractOperationPredicate) Matches(input ApiContract) 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/apimanagement/2024-05-01/api/version.go b/resource-manager/apimanagement/2024-05-01/api/version.go new file mode 100644 index 00000000000..399fdfa6a15 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/api/version.go @@ -0,0 +1,12 @@ +package api + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/api/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/README.md b/resource-manager/apimanagement/2024-05-01/apidiagnostic/README.md new file mode 100644 index 00000000000..48644332d5c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/README.md @@ -0,0 +1,234 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apidiagnostic` Documentation + +The `apidiagnostic` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apidiagnostic" +``` + + +### Client Initialization + +```go +client := apidiagnostic.NewApiDiagnosticClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiDiagnosticClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := apidiagnostic.NewApiDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "diagnosticIdValue") + +payload := apidiagnostic.DiagnosticContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, apidiagnostic.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiDiagnosticClient.Delete` + +```go +ctx := context.TODO() +id := apidiagnostic.NewApiDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "diagnosticIdValue") + +read, err := client.Delete(ctx, id, apidiagnostic.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiDiagnosticClient.Get` + +```go +ctx := context.TODO() +id := apidiagnostic.NewApiDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "diagnosticIdValue") + +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: `ApiDiagnosticClient.GetEntityTag` + +```go +ctx := context.TODO() +id := apidiagnostic.NewApiDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "diagnosticIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiDiagnosticClient.ListByService` + +```go +ctx := context.TODO() +id := apidiagnostic.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +// alternatively `client.ListByService(ctx, id, apidiagnostic.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, apidiagnostic.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ApiDiagnosticClient.Update` + +```go +ctx := context.TODO() +id := apidiagnostic.NewApiDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "diagnosticIdValue") + +payload := apidiagnostic.DiagnosticContract{ + // ... +} + + +read, err := client.Update(ctx, id, payload, apidiagnostic.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiDiagnosticClient.WorkspaceApiDiagnosticCreateOrUpdate` + +```go +ctx := context.TODO() +id := apidiagnostic.NewWorkspaceApiDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "diagnosticIdValue") + +payload := apidiagnostic.DiagnosticContract{ + // ... +} + + +read, err := client.WorkspaceApiDiagnosticCreateOrUpdate(ctx, id, payload, apidiagnostic.DefaultWorkspaceApiDiagnosticCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiDiagnosticClient.WorkspaceApiDiagnosticDelete` + +```go +ctx := context.TODO() +id := apidiagnostic.NewWorkspaceApiDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "diagnosticIdValue") + +read, err := client.WorkspaceApiDiagnosticDelete(ctx, id, apidiagnostic.DefaultWorkspaceApiDiagnosticDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiDiagnosticClient.WorkspaceApiDiagnosticGet` + +```go +ctx := context.TODO() +id := apidiagnostic.NewWorkspaceApiDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "diagnosticIdValue") + +read, err := client.WorkspaceApiDiagnosticGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiDiagnosticClient.WorkspaceApiDiagnosticGetEntityTag` + +```go +ctx := context.TODO() +id := apidiagnostic.NewWorkspaceApiDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "diagnosticIdValue") + +read, err := client.WorkspaceApiDiagnosticGetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiDiagnosticClient.WorkspaceApiDiagnosticListByWorkspace` + +```go +ctx := context.TODO() +id := apidiagnostic.NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue") + +// alternatively `client.WorkspaceApiDiagnosticListByWorkspace(ctx, id, apidiagnostic.DefaultWorkspaceApiDiagnosticListByWorkspaceOperationOptions())` can be used to do batched pagination +items, err := client.WorkspaceApiDiagnosticListByWorkspaceComplete(ctx, id, apidiagnostic.DefaultWorkspaceApiDiagnosticListByWorkspaceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ApiDiagnosticClient.WorkspaceApiDiagnosticUpdate` + +```go +ctx := context.TODO() +id := apidiagnostic.NewWorkspaceApiDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "diagnosticIdValue") + +payload := apidiagnostic.DiagnosticUpdateContract{ + // ... +} + + +read, err := client.WorkspaceApiDiagnosticUpdate(ctx, id, payload, apidiagnostic.DefaultWorkspaceApiDiagnosticUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/client.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/client.go new file mode 100644 index 00000000000..10bdb8741b2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/client.go @@ -0,0 +1,26 @@ +package apidiagnostic + +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 ApiDiagnosticClient struct { + Client *resourcemanager.Client +} + +func NewApiDiagnosticClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiDiagnosticClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apidiagnostic", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiDiagnosticClient: %+v", err) + } + + return &ApiDiagnosticClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/constants.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/constants.go new file mode 100644 index 00000000000..1afde676ffa --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/constants.go @@ -0,0 +1,256 @@ +package apidiagnostic + +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 AlwaysLog string + +const ( + AlwaysLogAllErrors AlwaysLog = "allErrors" +) + +func PossibleValuesForAlwaysLog() []string { + return []string{ + string(AlwaysLogAllErrors), + } +} + +func (s *AlwaysLog) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlwaysLog(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlwaysLog(input string) (*AlwaysLog, error) { + vals := map[string]AlwaysLog{ + "allerrors": AlwaysLogAllErrors, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlwaysLog(input) + return &out, nil +} + +type DataMaskingMode string + +const ( + DataMaskingModeHide DataMaskingMode = "Hide" + DataMaskingModeMask DataMaskingMode = "Mask" +) + +func PossibleValuesForDataMaskingMode() []string { + return []string{ + string(DataMaskingModeHide), + string(DataMaskingModeMask), + } +} + +func (s *DataMaskingMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataMaskingMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDataMaskingMode(input string) (*DataMaskingMode, error) { + vals := map[string]DataMaskingMode{ + "hide": DataMaskingModeHide, + "mask": DataMaskingModeMask, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataMaskingMode(input) + return &out, nil +} + +type HTTPCorrelationProtocol string + +const ( + HTTPCorrelationProtocolLegacy HTTPCorrelationProtocol = "Legacy" + HTTPCorrelationProtocolNone HTTPCorrelationProtocol = "None" + HTTPCorrelationProtocolWThreeC HTTPCorrelationProtocol = "W3C" +) + +func PossibleValuesForHTTPCorrelationProtocol() []string { + return []string{ + string(HTTPCorrelationProtocolLegacy), + string(HTTPCorrelationProtocolNone), + string(HTTPCorrelationProtocolWThreeC), + } +} + +func (s *HTTPCorrelationProtocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHTTPCorrelationProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHTTPCorrelationProtocol(input string) (*HTTPCorrelationProtocol, error) { + vals := map[string]HTTPCorrelationProtocol{ + "legacy": HTTPCorrelationProtocolLegacy, + "none": HTTPCorrelationProtocolNone, + "w3c": HTTPCorrelationProtocolWThreeC, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HTTPCorrelationProtocol(input) + return &out, nil +} + +type OperationNameFormat string + +const ( + OperationNameFormatName OperationNameFormat = "Name" + OperationNameFormatUrl OperationNameFormat = "Url" +) + +func PossibleValuesForOperationNameFormat() []string { + return []string{ + string(OperationNameFormatName), + string(OperationNameFormatUrl), + } +} + +func (s *OperationNameFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperationNameFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOperationNameFormat(input string) (*OperationNameFormat, error) { + vals := map[string]OperationNameFormat{ + "name": OperationNameFormatName, + "url": OperationNameFormatUrl, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OperationNameFormat(input) + return &out, nil +} + +type SamplingType string + +const ( + SamplingTypeFixed SamplingType = "fixed" +) + +func PossibleValuesForSamplingType() []string { + return []string{ + string(SamplingTypeFixed), + } +} + +func (s *SamplingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSamplingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSamplingType(input string) (*SamplingType, error) { + vals := map[string]SamplingType{ + "fixed": SamplingTypeFixed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SamplingType(input) + return &out, nil +} + +type Verbosity string + +const ( + VerbosityError Verbosity = "error" + VerbosityInformation Verbosity = "information" + VerbosityVerbose Verbosity = "verbose" +) + +func PossibleValuesForVerbosity() []string { + return []string{ + string(VerbosityError), + string(VerbosityInformation), + string(VerbosityVerbose), + } +} + +func (s *Verbosity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVerbosity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVerbosity(input string) (*Verbosity, error) { + vals := map[string]Verbosity{ + "error": VerbosityError, + "information": VerbosityInformation, + "verbose": VerbosityVerbose, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Verbosity(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/id_api.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/id_api.go new file mode 100644 index 00000000000..1c99bf5821c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/id_api.go @@ -0,0 +1,139 @@ +package apidiagnostic + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiId{}) +} + +var _ resourceids.ResourceId = &ApiId{} + +// ApiId is a struct representing the Resource ID for a Api +type ApiId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string +} + +// NewApiID returns a new ApiId struct +func NewApiID(subscriptionId string, resourceGroupName string, serviceName string, apiId string) ApiId { + return ApiId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + } +} + +// ParseApiID parses 'input' into a ApiId +func ParseApiID(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiIDInsensitively parses 'input' case-insensitively into a ApiId +// note: this method should only be used for API response data and not user input +func ParseApiIDInsensitively(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + return nil +} + +// ValidateApiID checks that 'input' can be parsed as a Api ID +func ValidateApiID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api ID +func (id ApiId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api ID +func (id ApiId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + } +} + +// String returns a human-readable description of this Api ID +func (id ApiId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + } + return fmt.Sprintf("Api (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/id_api_test.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/id_api_test.go new file mode 100644 index 00000000000..e4f054e22ef --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/id_api_test.go @@ -0,0 +1,327 @@ +package apidiagnostic + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiId{} + +func TestNewApiID(t *testing.T) { + id := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } +} + +func TestFormatApiID(t *testing.T) { + actual := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestParseApiIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestSegmentsForApiId(t *testing.T) { + segments := ApiId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/id_apidiagnostic.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/id_apidiagnostic.go new file mode 100644 index 00000000000..d2f0e00b2bb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/id_apidiagnostic.go @@ -0,0 +1,148 @@ +package apidiagnostic + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiDiagnosticId{}) +} + +var _ resourceids.ResourceId = &ApiDiagnosticId{} + +// ApiDiagnosticId is a struct representing the Resource ID for a Api Diagnostic +type ApiDiagnosticId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string + DiagnosticId string +} + +// NewApiDiagnosticID returns a new ApiDiagnosticId struct +func NewApiDiagnosticID(subscriptionId string, resourceGroupName string, serviceName string, apiId string, diagnosticId string) ApiDiagnosticId { + return ApiDiagnosticId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + DiagnosticId: diagnosticId, + } +} + +// ParseApiDiagnosticID parses 'input' into a ApiDiagnosticId +func ParseApiDiagnosticID(input string) (*ApiDiagnosticId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiDiagnosticId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiDiagnosticId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiDiagnosticIDInsensitively parses 'input' case-insensitively into a ApiDiagnosticId +// note: this method should only be used for API response data and not user input +func ParseApiDiagnosticIDInsensitively(input string) (*ApiDiagnosticId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiDiagnosticId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiDiagnosticId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiDiagnosticId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + if id.DiagnosticId, ok = input.Parsed["diagnosticId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "diagnosticId", input) + } + + return nil +} + +// ValidateApiDiagnosticID checks that 'input' can be parsed as a Api Diagnostic ID +func ValidateApiDiagnosticID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiDiagnosticID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api Diagnostic ID +func (id ApiDiagnosticId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s/diagnostics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId, id.DiagnosticId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api Diagnostic ID +func (id ApiDiagnosticId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + resourceids.StaticSegment("staticDiagnostics", "diagnostics", "diagnostics"), + resourceids.UserSpecifiedSegment("diagnosticId", "diagnosticIdValue"), + } +} + +// String returns a human-readable description of this Api Diagnostic ID +func (id ApiDiagnosticId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + fmt.Sprintf("Diagnostic: %q", id.DiagnosticId), + } + return fmt.Sprintf("Api Diagnostic (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/id_apidiagnostic_test.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/id_apidiagnostic_test.go new file mode 100644 index 00000000000..f94942020a3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/id_apidiagnostic_test.go @@ -0,0 +1,372 @@ +package apidiagnostic + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiDiagnosticId{} + +func TestNewApiDiagnosticID(t *testing.T) { + id := NewApiDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "diagnosticIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } + + if id.DiagnosticId != "diagnosticIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'DiagnosticId'", id.DiagnosticId, "diagnosticIdValue") + } +} + +func TestFormatApiDiagnosticID(t *testing.T) { + actual := NewApiDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "diagnosticIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/diagnostics/diagnosticIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiDiagnosticID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiDiagnosticId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/diagnostics", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/diagnostics/diagnosticIdValue", + Expected: &ApiDiagnosticId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + DiagnosticId: "diagnosticIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/diagnostics/diagnosticIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiDiagnosticID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.DiagnosticId != v.Expected.DiagnosticId { + t.Fatalf("Expected %q but got %q for DiagnosticId", v.Expected.DiagnosticId, actual.DiagnosticId) + } + + } +} + +func TestParseApiDiagnosticIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiDiagnosticId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/diagnostics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/dIaGnOsTiCs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/diagnostics/diagnosticIdValue", + Expected: &ApiDiagnosticId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + DiagnosticId: "diagnosticIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/diagnostics/diagnosticIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/dIaGnOsTiCs/dIaGnOsTiCiDvAlUe", + Expected: &ApiDiagnosticId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + DiagnosticId: "dIaGnOsTiCiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/dIaGnOsTiCs/dIaGnOsTiCiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiDiagnosticIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.DiagnosticId != v.Expected.DiagnosticId { + t.Fatalf("Expected %q but got %q for DiagnosticId", v.Expected.DiagnosticId, actual.DiagnosticId) + } + + } +} + +func TestSegmentsForApiDiagnosticId(t *testing.T) { + segments := ApiDiagnosticId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiDiagnosticId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/id_workspaceapi.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/id_workspaceapi.go new file mode 100644 index 00000000000..da3235190c0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/id_workspaceapi.go @@ -0,0 +1,148 @@ +package apidiagnostic + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceApiId{}) +} + +var _ resourceids.ResourceId = &WorkspaceApiId{} + +// WorkspaceApiId is a struct representing the Resource ID for a Workspace Api +type WorkspaceApiId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + ApiId string +} + +// NewWorkspaceApiID returns a new WorkspaceApiId struct +func NewWorkspaceApiID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, apiId string) WorkspaceApiId { + return WorkspaceApiId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + ApiId: apiId, + } +} + +// ParseWorkspaceApiID parses 'input' into a WorkspaceApiId +func ParseWorkspaceApiID(input string) (*WorkspaceApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceApiId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceApiIDInsensitively parses 'input' case-insensitively into a WorkspaceApiId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceApiIDInsensitively(input string) (*WorkspaceApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceApiId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceApiId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + return nil +} + +// ValidateWorkspaceApiID checks that 'input' can be parsed as a Workspace Api ID +func ValidateWorkspaceApiID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceApiID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Api ID +func (id WorkspaceApiId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/apis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.ApiId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Api ID +func (id WorkspaceApiId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + } +} + +// String returns a human-readable description of this Workspace Api ID +func (id WorkspaceApiId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Api: %q", id.ApiId), + } + return fmt.Sprintf("Workspace Api (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/id_workspaceapi_test.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/id_workspaceapi_test.go new file mode 100644 index 00000000000..bf453ecbd71 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/id_workspaceapi_test.go @@ -0,0 +1,372 @@ +package apidiagnostic + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceApiId{} + +func TestNewWorkspaceApiID(t *testing.T) { + id := NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } +} + +func TestFormatWorkspaceApiID(t *testing.T) { + actual := NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceApiID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue", + Expected: &WorkspaceApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceApiID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestParseWorkspaceApiIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue", + Expected: &WorkspaceApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE", + Expected: &WorkspaceApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + ApiId: "aPiIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceApiIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestSegmentsForWorkspaceApiId(t *testing.T) { + segments := WorkspaceApiId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceApiId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/id_workspaceapidiagnostic.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/id_workspaceapidiagnostic.go new file mode 100644 index 00000000000..19f41ce69ef --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/id_workspaceapidiagnostic.go @@ -0,0 +1,157 @@ +package apidiagnostic + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceApiDiagnosticId{}) +} + +var _ resourceids.ResourceId = &WorkspaceApiDiagnosticId{} + +// WorkspaceApiDiagnosticId is a struct representing the Resource ID for a Workspace Api Diagnostic +type WorkspaceApiDiagnosticId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + ApiId string + DiagnosticId string +} + +// NewWorkspaceApiDiagnosticID returns a new WorkspaceApiDiagnosticId struct +func NewWorkspaceApiDiagnosticID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, apiId string, diagnosticId string) WorkspaceApiDiagnosticId { + return WorkspaceApiDiagnosticId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + ApiId: apiId, + DiagnosticId: diagnosticId, + } +} + +// ParseWorkspaceApiDiagnosticID parses 'input' into a WorkspaceApiDiagnosticId +func ParseWorkspaceApiDiagnosticID(input string) (*WorkspaceApiDiagnosticId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceApiDiagnosticId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceApiDiagnosticId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceApiDiagnosticIDInsensitively parses 'input' case-insensitively into a WorkspaceApiDiagnosticId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceApiDiagnosticIDInsensitively(input string) (*WorkspaceApiDiagnosticId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceApiDiagnosticId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceApiDiagnosticId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceApiDiagnosticId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + if id.DiagnosticId, ok = input.Parsed["diagnosticId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "diagnosticId", input) + } + + return nil +} + +// ValidateWorkspaceApiDiagnosticID checks that 'input' can be parsed as a Workspace Api Diagnostic ID +func ValidateWorkspaceApiDiagnosticID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceApiDiagnosticID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Api Diagnostic ID +func (id WorkspaceApiDiagnosticId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/apis/%s/diagnostics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.ApiId, id.DiagnosticId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Api Diagnostic ID +func (id WorkspaceApiDiagnosticId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + resourceids.StaticSegment("staticDiagnostics", "diagnostics", "diagnostics"), + resourceids.UserSpecifiedSegment("diagnosticId", "diagnosticIdValue"), + } +} + +// String returns a human-readable description of this Workspace Api Diagnostic ID +func (id WorkspaceApiDiagnosticId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Api: %q", id.ApiId), + fmt.Sprintf("Diagnostic: %q", id.DiagnosticId), + } + return fmt.Sprintf("Workspace Api Diagnostic (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/id_workspaceapidiagnostic_test.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/id_workspaceapidiagnostic_test.go new file mode 100644 index 00000000000..210cdc0ff7e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/id_workspaceapidiagnostic_test.go @@ -0,0 +1,417 @@ +package apidiagnostic + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceApiDiagnosticId{} + +func TestNewWorkspaceApiDiagnosticID(t *testing.T) { + id := NewWorkspaceApiDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "diagnosticIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } + + if id.DiagnosticId != "diagnosticIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'DiagnosticId'", id.DiagnosticId, "diagnosticIdValue") + } +} + +func TestFormatWorkspaceApiDiagnosticID(t *testing.T) { + actual := NewWorkspaceApiDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "diagnosticIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/diagnostics/diagnosticIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceApiDiagnosticID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceApiDiagnosticId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/diagnostics", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/diagnostics/diagnosticIdValue", + Expected: &WorkspaceApiDiagnosticId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ApiId: "apiIdValue", + DiagnosticId: "diagnosticIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/diagnostics/diagnosticIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceApiDiagnosticID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.DiagnosticId != v.Expected.DiagnosticId { + t.Fatalf("Expected %q but got %q for DiagnosticId", v.Expected.DiagnosticId, actual.DiagnosticId) + } + + } +} + +func TestParseWorkspaceApiDiagnosticIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceApiDiagnosticId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/diagnostics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE/dIaGnOsTiCs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/diagnostics/diagnosticIdValue", + Expected: &WorkspaceApiDiagnosticId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ApiId: "apiIdValue", + DiagnosticId: "diagnosticIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/diagnostics/diagnosticIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE/dIaGnOsTiCs/dIaGnOsTiCiDvAlUe", + Expected: &WorkspaceApiDiagnosticId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + ApiId: "aPiIdVaLuE", + DiagnosticId: "dIaGnOsTiCiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE/dIaGnOsTiCs/dIaGnOsTiCiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceApiDiagnosticIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.DiagnosticId != v.Expected.DiagnosticId { + t.Fatalf("Expected %q but got %q for DiagnosticId", v.Expected.DiagnosticId, actual.DiagnosticId) + } + + } +} + +func TestSegmentsForWorkspaceApiDiagnosticId(t *testing.T) { + segments := WorkspaceApiDiagnosticId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceApiDiagnosticId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_createorupdate.go new file mode 100644 index 00000000000..2551a5d1445 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_createorupdate.go @@ -0,0 +1,88 @@ +package apidiagnostic + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DiagnosticContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c ApiDiagnosticClient) CreateOrUpdate(ctx context.Context, id ApiDiagnosticId, input DiagnosticContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 DiagnosticContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_delete.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_delete.go new file mode 100644 index 00000000000..a781c7b154b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_delete.go @@ -0,0 +1,76 @@ +package apidiagnostic + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c ApiDiagnosticClient) Delete(ctx context.Context, id ApiDiagnosticId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_get.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_get.go new file mode 100644 index 00000000000..bb113001b36 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_get.go @@ -0,0 +1,54 @@ +package apidiagnostic + +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 *DiagnosticContract +} + +// Get ... +func (c ApiDiagnosticClient) Get(ctx context.Context, id ApiDiagnosticId) (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 DiagnosticContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_getentitytag.go new file mode 100644 index 00000000000..312e0f37414 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_getentitytag.go @@ -0,0 +1,46 @@ +package apidiagnostic + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c ApiDiagnosticClient) GetEntityTag(ctx context.Context, id ApiDiagnosticId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_listbyservice.go new file mode 100644 index 00000000000..96b6f06f674 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_listbyservice.go @@ -0,0 +1,141 @@ +package apidiagnostic + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DiagnosticContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []DiagnosticContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c ApiDiagnosticClient) ListByService(ctx context.Context, id ApiId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/diagnostics", 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 *[]DiagnosticContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c ApiDiagnosticClient) ListByServiceComplete(ctx context.Context, id ApiId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, DiagnosticContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiDiagnosticClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ApiId, options ListByServiceOperationOptions, predicate DiagnosticContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]DiagnosticContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_update.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_update.go new file mode 100644 index 00000000000..00ef4533a35 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_update.go @@ -0,0 +1,87 @@ +package apidiagnostic + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DiagnosticContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c ApiDiagnosticClient) Update(ctx context.Context, id ApiDiagnosticId, input DiagnosticContract, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 DiagnosticContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_workspaceapidiagnosticcreateorupdate.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_workspaceapidiagnosticcreateorupdate.go new file mode 100644 index 00000000000..538d4891707 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_workspaceapidiagnosticcreateorupdate.go @@ -0,0 +1,88 @@ +package apidiagnostic + +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 WorkspaceApiDiagnosticCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DiagnosticContract +} + +type WorkspaceApiDiagnosticCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceApiDiagnosticCreateOrUpdateOperationOptions() WorkspaceApiDiagnosticCreateOrUpdateOperationOptions { + return WorkspaceApiDiagnosticCreateOrUpdateOperationOptions{} +} + +func (o WorkspaceApiDiagnosticCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceApiDiagnosticCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiDiagnosticCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceApiDiagnosticCreateOrUpdate ... +func (c ApiDiagnosticClient) WorkspaceApiDiagnosticCreateOrUpdate(ctx context.Context, id WorkspaceApiDiagnosticId, input DiagnosticContract, options WorkspaceApiDiagnosticCreateOrUpdateOperationOptions) (result WorkspaceApiDiagnosticCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 DiagnosticContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_workspaceapidiagnosticdelete.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_workspaceapidiagnosticdelete.go new file mode 100644 index 00000000000..6b4dab14250 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_workspaceapidiagnosticdelete.go @@ -0,0 +1,76 @@ +package apidiagnostic + +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 WorkspaceApiDiagnosticDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type WorkspaceApiDiagnosticDeleteOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceApiDiagnosticDeleteOperationOptions() WorkspaceApiDiagnosticDeleteOperationOptions { + return WorkspaceApiDiagnosticDeleteOperationOptions{} +} + +func (o WorkspaceApiDiagnosticDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceApiDiagnosticDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiDiagnosticDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceApiDiagnosticDelete ... +func (c ApiDiagnosticClient) WorkspaceApiDiagnosticDelete(ctx context.Context, id WorkspaceApiDiagnosticId, options WorkspaceApiDiagnosticDeleteOperationOptions) (result WorkspaceApiDiagnosticDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_workspaceapidiagnosticget.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_workspaceapidiagnosticget.go new file mode 100644 index 00000000000..18c3378fec4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_workspaceapidiagnosticget.go @@ -0,0 +1,54 @@ +package apidiagnostic + +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 WorkspaceApiDiagnosticGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DiagnosticContract +} + +// WorkspaceApiDiagnosticGet ... +func (c ApiDiagnosticClient) WorkspaceApiDiagnosticGet(ctx context.Context, id WorkspaceApiDiagnosticId) (result WorkspaceApiDiagnosticGetOperationResponse, 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 DiagnosticContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_workspaceapidiagnosticgetentitytag.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_workspaceapidiagnosticgetentitytag.go new file mode 100644 index 00000000000..c5e6c126d63 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_workspaceapidiagnosticgetentitytag.go @@ -0,0 +1,46 @@ +package apidiagnostic + +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 WorkspaceApiDiagnosticGetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceApiDiagnosticGetEntityTag ... +func (c ApiDiagnosticClient) WorkspaceApiDiagnosticGetEntityTag(ctx context.Context, id WorkspaceApiDiagnosticId) (result WorkspaceApiDiagnosticGetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_workspaceapidiagnosticlistbyworkspace.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_workspaceapidiagnosticlistbyworkspace.go new file mode 100644 index 00000000000..1b1cd745d3f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_workspaceapidiagnosticlistbyworkspace.go @@ -0,0 +1,141 @@ +package apidiagnostic + +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 WorkspaceApiDiagnosticListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DiagnosticContract +} + +type WorkspaceApiDiagnosticListByWorkspaceCompleteResult struct { + LatestHttpResponse *http.Response + Items []DiagnosticContract +} + +type WorkspaceApiDiagnosticListByWorkspaceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultWorkspaceApiDiagnosticListByWorkspaceOperationOptions() WorkspaceApiDiagnosticListByWorkspaceOperationOptions { + return WorkspaceApiDiagnosticListByWorkspaceOperationOptions{} +} + +func (o WorkspaceApiDiagnosticListByWorkspaceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceApiDiagnosticListByWorkspaceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiDiagnosticListByWorkspaceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspaceApiDiagnosticListByWorkspaceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceApiDiagnosticListByWorkspaceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceApiDiagnosticListByWorkspace ... +func (c ApiDiagnosticClient) WorkspaceApiDiagnosticListByWorkspace(ctx context.Context, id WorkspaceApiId, options WorkspaceApiDiagnosticListByWorkspaceOperationOptions) (result WorkspaceApiDiagnosticListByWorkspaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspaceApiDiagnosticListByWorkspaceCustomPager{}, + Path: fmt.Sprintf("%s/diagnostics", 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 *[]DiagnosticContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceApiDiagnosticListByWorkspaceComplete retrieves all the results into a single object +func (c ApiDiagnosticClient) WorkspaceApiDiagnosticListByWorkspaceComplete(ctx context.Context, id WorkspaceApiId, options WorkspaceApiDiagnosticListByWorkspaceOperationOptions) (WorkspaceApiDiagnosticListByWorkspaceCompleteResult, error) { + return c.WorkspaceApiDiagnosticListByWorkspaceCompleteMatchingPredicate(ctx, id, options, DiagnosticContractOperationPredicate{}) +} + +// WorkspaceApiDiagnosticListByWorkspaceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiDiagnosticClient) WorkspaceApiDiagnosticListByWorkspaceCompleteMatchingPredicate(ctx context.Context, id WorkspaceApiId, options WorkspaceApiDiagnosticListByWorkspaceOperationOptions, predicate DiagnosticContractOperationPredicate) (result WorkspaceApiDiagnosticListByWorkspaceCompleteResult, err error) { + items := make([]DiagnosticContract, 0) + + resp, err := c.WorkspaceApiDiagnosticListByWorkspace(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceApiDiagnosticListByWorkspaceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_workspaceapidiagnosticupdate.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_workspaceapidiagnosticupdate.go new file mode 100644 index 00000000000..c326f3478f7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/method_workspaceapidiagnosticupdate.go @@ -0,0 +1,87 @@ +package apidiagnostic + +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 WorkspaceApiDiagnosticUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DiagnosticContract +} + +type WorkspaceApiDiagnosticUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceApiDiagnosticUpdateOperationOptions() WorkspaceApiDiagnosticUpdateOperationOptions { + return WorkspaceApiDiagnosticUpdateOperationOptions{} +} + +func (o WorkspaceApiDiagnosticUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceApiDiagnosticUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiDiagnosticUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceApiDiagnosticUpdate ... +func (c ApiDiagnosticClient) WorkspaceApiDiagnosticUpdate(ctx context.Context, id WorkspaceApiDiagnosticId, input DiagnosticUpdateContract, options WorkspaceApiDiagnosticUpdateOperationOptions) (result WorkspaceApiDiagnosticUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 DiagnosticContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_bodydiagnosticsettings.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_bodydiagnosticsettings.go new file mode 100644 index 00000000000..dad67d6d8b4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_bodydiagnosticsettings.go @@ -0,0 +1,8 @@ +package apidiagnostic + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BodyDiagnosticSettings struct { + Bytes *int64 `json:"bytes,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_datamasking.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_datamasking.go new file mode 100644 index 00000000000..e4224370d26 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_datamasking.go @@ -0,0 +1,9 @@ +package apidiagnostic + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataMasking struct { + Headers *[]DataMaskingEntity `json:"headers,omitempty"` + QueryParams *[]DataMaskingEntity `json:"queryParams,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_datamaskingentity.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_datamaskingentity.go new file mode 100644 index 00000000000..232eb3022ce --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_datamaskingentity.go @@ -0,0 +1,9 @@ +package apidiagnostic + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataMaskingEntity struct { + Mode *DataMaskingMode `json:"mode,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_diagnosticcontract.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_diagnosticcontract.go new file mode 100644 index 00000000000..c11ca5d935f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_diagnosticcontract.go @@ -0,0 +1,11 @@ +package apidiagnostic + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DiagnosticContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_diagnosticcontractproperties.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_diagnosticcontractproperties.go new file mode 100644 index 00000000000..72088ff5c55 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_diagnosticcontractproperties.go @@ -0,0 +1,17 @@ +package apidiagnostic + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticContractProperties struct { + AlwaysLog *AlwaysLog `json:"alwaysLog,omitempty"` + Backend *PipelineDiagnosticSettings `json:"backend,omitempty"` + Frontend *PipelineDiagnosticSettings `json:"frontend,omitempty"` + HTTPCorrelationProtocol *HTTPCorrelationProtocol `json:"httpCorrelationProtocol,omitempty"` + LogClientIP *bool `json:"logClientIp,omitempty"` + LoggerId string `json:"loggerId"` + Metrics *bool `json:"metrics,omitempty"` + OperationNameFormat *OperationNameFormat `json:"operationNameFormat,omitempty"` + Sampling *SamplingSettings `json:"sampling,omitempty"` + Verbosity *Verbosity `json:"verbosity,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_diagnosticcontractupdateproperties.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_diagnosticcontractupdateproperties.go new file mode 100644 index 00000000000..a0233c241e1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_diagnosticcontractupdateproperties.go @@ -0,0 +1,17 @@ +package apidiagnostic + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticContractUpdateProperties struct { + AlwaysLog *AlwaysLog `json:"alwaysLog,omitempty"` + Backend *PipelineDiagnosticSettings `json:"backend,omitempty"` + Frontend *PipelineDiagnosticSettings `json:"frontend,omitempty"` + HTTPCorrelationProtocol *HTTPCorrelationProtocol `json:"httpCorrelationProtocol,omitempty"` + LogClientIP *bool `json:"logClientIp,omitempty"` + LoggerId *string `json:"loggerId,omitempty"` + Metrics *bool `json:"metrics,omitempty"` + OperationNameFormat *OperationNameFormat `json:"operationNameFormat,omitempty"` + Sampling *SamplingSettings `json:"sampling,omitempty"` + Verbosity *Verbosity `json:"verbosity,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_diagnosticupdatecontract.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_diagnosticupdatecontract.go new file mode 100644 index 00000000000..6de65998b31 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_diagnosticupdatecontract.go @@ -0,0 +1,11 @@ +package apidiagnostic + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticUpdateContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DiagnosticContractUpdateProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_httpmessagediagnostic.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_httpmessagediagnostic.go new file mode 100644 index 00000000000..03079feace5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_httpmessagediagnostic.go @@ -0,0 +1,10 @@ +package apidiagnostic + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HTTPMessageDiagnostic struct { + Body *BodyDiagnosticSettings `json:"body,omitempty"` + DataMasking *DataMasking `json:"dataMasking,omitempty"` + Headers *[]string `json:"headers,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_pipelinediagnosticsettings.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_pipelinediagnosticsettings.go new file mode 100644 index 00000000000..902e9ce6a62 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_pipelinediagnosticsettings.go @@ -0,0 +1,9 @@ +package apidiagnostic + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PipelineDiagnosticSettings struct { + Request *HTTPMessageDiagnostic `json:"request,omitempty"` + Response *HTTPMessageDiagnostic `json:"response,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_samplingsettings.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_samplingsettings.go new file mode 100644 index 00000000000..c6e6b44983d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/model_samplingsettings.go @@ -0,0 +1,9 @@ +package apidiagnostic + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SamplingSettings struct { + Percentage *float64 `json:"percentage,omitempty"` + SamplingType *SamplingType `json:"samplingType,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apidiagnostic/predicates.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/predicates.go new file mode 100644 index 00000000000..0ab615cd8e8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/predicates.go @@ -0,0 +1,27 @@ +package apidiagnostic + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DiagnosticContractOperationPredicate) Matches(input DiagnosticContract) 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/apimanagement/2024-05-01/apidiagnostic/version.go b/resource-manager/apimanagement/2024-05-01/apidiagnostic/version.go new file mode 100644 index 00000000000..b56bb21ecac --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apidiagnostic/version.go @@ -0,0 +1,12 @@ +package apidiagnostic + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apidiagnostic/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apigateway/README.md b/resource-manager/apimanagement/2024-05-01/apigateway/README.md new file mode 100644 index 00000000000..9667631849a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigateway/README.md @@ -0,0 +1,117 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apigateway` Documentation + +The `apigateway` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apigateway" +``` + + +### Client Initialization + +```go +client := apigateway.NewApiGatewayClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiGatewayClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := apigateway.NewGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayValue") + +payload := apigateway.ApiManagementGatewayResource{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ApiGatewayClient.Delete` + +```go +ctx := context.TODO() +id := apigateway.NewGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ApiGatewayClient.Get` + +```go +ctx := context.TODO() +id := apigateway.NewGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayValue") + +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: `ApiGatewayClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ApiGatewayClient.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: `ApiGatewayClient.Update` + +```go +ctx := context.TODO() +id := apigateway.NewGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayValue") + +payload := apigateway.ApiManagementGatewayUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/apigateway/client.go b/resource-manager/apimanagement/2024-05-01/apigateway/client.go new file mode 100644 index 00000000000..2ac4cbaf18e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigateway/client.go @@ -0,0 +1,26 @@ +package apigateway + +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 ApiGatewayClient struct { + Client *resourcemanager.Client +} + +func NewApiGatewayClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiGatewayClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apigateway", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiGatewayClient: %+v", err) + } + + return &ApiGatewayClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apigateway/constants.go b/resource-manager/apimanagement/2024-05-01/apigateway/constants.go new file mode 100644 index 00000000000..98f0c7770b7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigateway/constants.go @@ -0,0 +1,98 @@ +package apigateway + +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 ApiGatewaySkuType string + +const ( + ApiGatewaySkuTypeStandard ApiGatewaySkuType = "Standard" + ApiGatewaySkuTypeWorkspaceGatewayPremium ApiGatewaySkuType = "WorkspaceGatewayPremium" + ApiGatewaySkuTypeWorkspaceGatewayStandard ApiGatewaySkuType = "WorkspaceGatewayStandard" +) + +func PossibleValuesForApiGatewaySkuType() []string { + return []string{ + string(ApiGatewaySkuTypeStandard), + string(ApiGatewaySkuTypeWorkspaceGatewayPremium), + string(ApiGatewaySkuTypeWorkspaceGatewayStandard), + } +} + +func (s *ApiGatewaySkuType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseApiGatewaySkuType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseApiGatewaySkuType(input string) (*ApiGatewaySkuType, error) { + vals := map[string]ApiGatewaySkuType{ + "standard": ApiGatewaySkuTypeStandard, + "workspacegatewaypremium": ApiGatewaySkuTypeWorkspaceGatewayPremium, + "workspacegatewaystandard": ApiGatewaySkuTypeWorkspaceGatewayStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ApiGatewaySkuType(input) + return &out, nil +} + +type VirtualNetworkType string + +const ( + VirtualNetworkTypeExternal VirtualNetworkType = "External" + VirtualNetworkTypeInternal VirtualNetworkType = "Internal" + VirtualNetworkTypeNone VirtualNetworkType = "None" +) + +func PossibleValuesForVirtualNetworkType() []string { + return []string{ + string(VirtualNetworkTypeExternal), + string(VirtualNetworkTypeInternal), + string(VirtualNetworkTypeNone), + } +} + +func (s *VirtualNetworkType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVirtualNetworkType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVirtualNetworkType(input string) (*VirtualNetworkType, error) { + vals := map[string]VirtualNetworkType{ + "external": VirtualNetworkTypeExternal, + "internal": VirtualNetworkTypeInternal, + "none": VirtualNetworkTypeNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VirtualNetworkType(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apigateway/id_gateway.go b/resource-manager/apimanagement/2024-05-01/apigateway/id_gateway.go new file mode 100644 index 00000000000..ff4cb6b9891 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigateway/id_gateway.go @@ -0,0 +1,130 @@ +package apigateway + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&GatewayId{}) +} + +var _ resourceids.ResourceId = &GatewayId{} + +// GatewayId is a struct representing the Resource ID for a Gateway +type GatewayId struct { + SubscriptionId string + ResourceGroupName string + GatewayName string +} + +// NewGatewayID returns a new GatewayId struct +func NewGatewayID(subscriptionId string, resourceGroupName string, gatewayName string) GatewayId { + return GatewayId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + GatewayName: gatewayName, + } +} + +// ParseGatewayID parses 'input' into a GatewayId +func ParseGatewayID(input string) (*GatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&GatewayId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGatewayIDInsensitively parses 'input' case-insensitively into a GatewayId +// note: this method should only be used for API response data and not user input +func ParseGatewayIDInsensitively(input string) (*GatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&GatewayId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GatewayId) 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.GatewayName, ok = input.Parsed["gatewayName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "gatewayName", input) + } + + return nil +} + +// ValidateGatewayID checks that 'input' can be parsed as a Gateway ID +func ValidateGatewayID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseGatewayID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Gateway ID +func (id GatewayId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/gateways/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.GatewayName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Gateway ID +func (id GatewayId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticGateways", "gateways", "gateways"), + resourceids.UserSpecifiedSegment("gatewayName", "gatewayValue"), + } +} + +// String returns a human-readable description of this Gateway ID +func (id GatewayId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Gateway Name: %q", id.GatewayName), + } + return fmt.Sprintf("Gateway (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apigateway/id_gateway_test.go b/resource-manager/apimanagement/2024-05-01/apigateway/id_gateway_test.go new file mode 100644 index 00000000000..bc90ce536be --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigateway/id_gateway_test.go @@ -0,0 +1,282 @@ +package apigateway + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GatewayId{} + +func TestNewGatewayID(t *testing.T) { + id := NewGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.GatewayName != "gatewayValue" { + t.Fatalf("Expected %q but got %q for Segment 'GatewayName'", id.GatewayName, "gatewayValue") + } +} + +func TestFormatGatewayID(t *testing.T) { + actual := NewGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways/gatewayValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGatewayID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways/gatewayValue", + Expected: &GatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GatewayName: "gatewayValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways/gatewayValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGatewayID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GatewayName != v.Expected.GatewayName { + t.Fatalf("Expected %q but got %q for GatewayName", v.Expected.GatewayName, actual.GatewayName) + } + + } +} + +func TestParseGatewayIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/gAtEwAyS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways/gatewayValue", + Expected: &GatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GatewayName: "gatewayValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways/gatewayValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/gAtEwAyS/gAtEwAyVaLuE", + Expected: &GatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + GatewayName: "gAtEwAyVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/gAtEwAyS/gAtEwAyVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGatewayIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GatewayName != v.Expected.GatewayName { + t.Fatalf("Expected %q but got %q for GatewayName", v.Expected.GatewayName, actual.GatewayName) + } + + } +} + +func TestSegmentsForGatewayId(t *testing.T) { + segments := GatewayId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GatewayId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apigateway/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/apigateway/method_createorupdate.go new file mode 100644 index 00000000000..fb019139cbe --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigateway/method_createorupdate.go @@ -0,0 +1,75 @@ +package apigateway + +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 *ApiManagementGatewayResource +} + +// CreateOrUpdate ... +func (c ApiGatewayClient) CreateOrUpdate(ctx context.Context, id GatewayId, input ApiManagementGatewayResource) (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 ApiGatewayClient) CreateOrUpdateThenPoll(ctx context.Context, id GatewayId, input ApiManagementGatewayResource) 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/apimanagement/2024-05-01/apigateway/method_delete.go b/resource-manager/apimanagement/2024-05-01/apigateway/method_delete.go new file mode 100644 index 00000000000..0176c2a7edb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigateway/method_delete.go @@ -0,0 +1,71 @@ +package apigateway + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ApiManagementGatewayResource +} + +// Delete ... +func (c ApiGatewayClient) Delete(ctx context.Context, id GatewayId) (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 ApiGatewayClient) DeleteThenPoll(ctx context.Context, id GatewayId) 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/apimanagement/2024-05-01/apigateway/method_get.go b/resource-manager/apimanagement/2024-05-01/apigateway/method_get.go new file mode 100644 index 00000000000..32444f86cfd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigateway/method_get.go @@ -0,0 +1,54 @@ +package apigateway + +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 *ApiManagementGatewayResource +} + +// Get ... +func (c ApiGatewayClient) Get(ctx context.Context, id GatewayId) (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 ApiManagementGatewayResource + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apigateway/method_list.go b/resource-manager/apimanagement/2024-05-01/apigateway/method_list.go new file mode 100644 index 00000000000..8c3247e24fb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigateway/method_list.go @@ -0,0 +1,106 @@ +package apigateway + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ApiManagementGatewayResource +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ApiManagementGatewayResource +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ApiGatewayClient) List(ctx context.Context, id commonids.SubscriptionId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.ApiManagement/gateways", 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 *[]ApiManagementGatewayResource `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 ApiGatewayClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, ApiManagementGatewayResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiGatewayClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ApiManagementGatewayResourceOperationPredicate) (result ListCompleteResult, err error) { + items := make([]ApiManagementGatewayResource, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apigateway/method_listbyresourcegroup.go b/resource-manager/apimanagement/2024-05-01/apigateway/method_listbyresourcegroup.go new file mode 100644 index 00000000000..32a7ea971e5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigateway/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package apigateway + +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 *[]ApiManagementGatewayResource +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []ApiManagementGatewayResource +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c ApiGatewayClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.ApiManagement/gateways", 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 *[]ApiManagementGatewayResource `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 ApiGatewayClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, ApiManagementGatewayResourceOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiGatewayClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ApiManagementGatewayResourceOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]ApiManagementGatewayResource, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apigateway/method_update.go b/resource-manager/apimanagement/2024-05-01/apigateway/method_update.go new file mode 100644 index 00000000000..9df639cbffe --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigateway/method_update.go @@ -0,0 +1,75 @@ +package apigateway + +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 *ApiManagementGatewayResource +} + +// Update ... +func (c ApiGatewayClient) Update(ctx context.Context, id GatewayId, input ApiManagementGatewayUpdateParameters) (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 ApiGatewayClient) UpdateThenPoll(ctx context.Context, id GatewayId, input ApiManagementGatewayUpdateParameters) 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/apimanagement/2024-05-01/apigateway/model_apimanagementgatewaybaseproperties.go b/resource-manager/apimanagement/2024-05-01/apigateway/model_apimanagementgatewaybaseproperties.go new file mode 100644 index 00000000000..437fdc56121 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigateway/model_apimanagementgatewaybaseproperties.go @@ -0,0 +1,32 @@ +package apigateway + +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 ApiManagementGatewayBaseProperties struct { + Backend *BackendConfiguration `json:"backend,omitempty"` + ConfigurationApi *GatewayConfigurationApi `json:"configurationApi,omitempty"` + CreatedAtUtc *string `json:"createdAtUtc,omitempty"` + Frontend *FrontendConfiguration `json:"frontend,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + TargetProvisioningState *string `json:"targetProvisioningState,omitempty"` + VirtualNetworkType *VirtualNetworkType `json:"virtualNetworkType,omitempty"` +} + +func (o *ApiManagementGatewayBaseProperties) GetCreatedAtUtcAsTime() (*time.Time, error) { + if o.CreatedAtUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedAtUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *ApiManagementGatewayBaseProperties) SetCreatedAtUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedAtUtc = &formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/apigateway/model_apimanagementgatewayresource.go b/resource-manager/apimanagement/2024-05-01/apigateway/model_apimanagementgatewayresource.go new file mode 100644 index 00000000000..09cc9adf8e8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigateway/model_apimanagementgatewayresource.go @@ -0,0 +1,20 @@ +package apigateway + +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 ApiManagementGatewayResource struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties ApiManagementGatewayBaseProperties `json:"properties"` + Sku ApiManagementGatewaySkuProperties `json:"sku"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apigateway/model_apimanagementgatewayskuproperties.go b/resource-manager/apimanagement/2024-05-01/apigateway/model_apimanagementgatewayskuproperties.go new file mode 100644 index 00000000000..d04d7e73975 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigateway/model_apimanagementgatewayskuproperties.go @@ -0,0 +1,9 @@ +package apigateway + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementGatewaySkuProperties struct { + Capacity *int64 `json:"capacity,omitempty"` + Name ApiGatewaySkuType `json:"name"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apigateway/model_apimanagementgatewayskupropertiesforpatch.go b/resource-manager/apimanagement/2024-05-01/apigateway/model_apimanagementgatewayskupropertiesforpatch.go new file mode 100644 index 00000000000..9dec0e34c14 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigateway/model_apimanagementgatewayskupropertiesforpatch.go @@ -0,0 +1,9 @@ +package apigateway + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementGatewaySkuPropertiesForPatch struct { + Capacity *int64 `json:"capacity,omitempty"` + Name *ApiGatewaySkuType `json:"name,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apigateway/model_apimanagementgatewayupdateparameters.go b/resource-manager/apimanagement/2024-05-01/apigateway/model_apimanagementgatewayupdateparameters.go new file mode 100644 index 00000000000..0e85c3314c8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigateway/model_apimanagementgatewayupdateparameters.go @@ -0,0 +1,14 @@ +package apigateway + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementGatewayUpdateParameters struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ApiManagementGatewayBaseProperties `json:"properties,omitempty"` + Sku *ApiManagementGatewaySkuPropertiesForPatch `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apigateway/model_backendconfiguration.go b/resource-manager/apimanagement/2024-05-01/apigateway/model_backendconfiguration.go new file mode 100644 index 00000000000..915cd54d6af --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigateway/model_backendconfiguration.go @@ -0,0 +1,8 @@ +package apigateway + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackendConfiguration struct { + Subnet *BackendSubnetConfiguration `json:"subnet,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apigateway/model_backendsubnetconfiguration.go b/resource-manager/apimanagement/2024-05-01/apigateway/model_backendsubnetconfiguration.go new file mode 100644 index 00000000000..d7d77ed424f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigateway/model_backendsubnetconfiguration.go @@ -0,0 +1,8 @@ +package apigateway + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackendSubnetConfiguration struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apigateway/model_frontendconfiguration.go b/resource-manager/apimanagement/2024-05-01/apigateway/model_frontendconfiguration.go new file mode 100644 index 00000000000..f9432da0ec1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigateway/model_frontendconfiguration.go @@ -0,0 +1,8 @@ +package apigateway + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FrontendConfiguration struct { + DefaultHostname *string `json:"defaultHostname,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apigateway/model_gatewayconfigurationapi.go b/resource-manager/apimanagement/2024-05-01/apigateway/model_gatewayconfigurationapi.go new file mode 100644 index 00000000000..1140b1c3459 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigateway/model_gatewayconfigurationapi.go @@ -0,0 +1,8 @@ +package apigateway + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewayConfigurationApi struct { + Hostname *string `json:"hostname,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apigateway/predicates.go b/resource-manager/apimanagement/2024-05-01/apigateway/predicates.go new file mode 100644 index 00000000000..69d39b4a39b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigateway/predicates.go @@ -0,0 +1,37 @@ +package apigateway + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementGatewayResourceOperationPredicate struct { + Etag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p ApiManagementGatewayResourceOperationPredicate) Matches(input ApiManagementGatewayResource) bool { + + if p.Etag != nil && (input.Etag == nil || *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/apimanagement/2024-05-01/apigateway/version.go b/resource-manager/apimanagement/2024-05-01/apigateway/version.go new file mode 100644 index 00000000000..ceac1352934 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigateway/version.go @@ -0,0 +1,12 @@ +package apigateway + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apigateway/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/README.md b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/README.md new file mode 100644 index 00000000000..2744cb7ac29 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection` Documentation + +The `apigatewayconfigconnection` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection" +``` + + +### Client Initialization + +```go +client := apigatewayconfigconnection.NewApiGatewayConfigConnectionClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiGatewayConfigConnectionClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := apigatewayconfigconnection.NewConfigConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayValue", "configConnectionValue") + +payload := apigatewayconfigconnection.ApiManagementGatewayConfigConnectionResource{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ApiGatewayConfigConnectionClient.Delete` + +```go +ctx := context.TODO() +id := apigatewayconfigconnection.NewConfigConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayValue", "configConnectionValue") + +if err := client.DeleteThenPoll(ctx, id, apigatewayconfigconnection.DefaultDeleteOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `ApiGatewayConfigConnectionClient.Get` + +```go +ctx := context.TODO() +id := apigatewayconfigconnection.NewConfigConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayValue", "configConnectionValue") + +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: `ApiGatewayConfigConnectionClient.ListByGateway` + +```go +ctx := context.TODO() +id := apigatewayconfigconnection.NewGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayValue") + +// alternatively `client.ListByGateway(ctx, id)` can be used to do batched pagination +items, err := client.ListByGatewayComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/client.go b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/client.go new file mode 100644 index 00000000000..408e8af0cdf --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/client.go @@ -0,0 +1,26 @@ +package apigatewayconfigconnection + +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 ApiGatewayConfigConnectionClient struct { + Client *resourcemanager.Client +} + +func NewApiGatewayConfigConnectionClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiGatewayConfigConnectionClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apigatewayconfigconnection", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiGatewayConfigConnectionClient: %+v", err) + } + + return &ApiGatewayConfigConnectionClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/id_configconnection.go b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/id_configconnection.go new file mode 100644 index 00000000000..3313957c1f5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/id_configconnection.go @@ -0,0 +1,139 @@ +package apigatewayconfigconnection + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ConfigConnectionId{}) +} + +var _ resourceids.ResourceId = &ConfigConnectionId{} + +// ConfigConnectionId is a struct representing the Resource ID for a Config Connection +type ConfigConnectionId struct { + SubscriptionId string + ResourceGroupName string + GatewayName string + ConfigConnectionName string +} + +// NewConfigConnectionID returns a new ConfigConnectionId struct +func NewConfigConnectionID(subscriptionId string, resourceGroupName string, gatewayName string, configConnectionName string) ConfigConnectionId { + return ConfigConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + GatewayName: gatewayName, + ConfigConnectionName: configConnectionName, + } +} + +// ParseConfigConnectionID parses 'input' into a ConfigConnectionId +func ParseConfigConnectionID(input string) (*ConfigConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ConfigConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ConfigConnectionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseConfigConnectionIDInsensitively parses 'input' case-insensitively into a ConfigConnectionId +// note: this method should only be used for API response data and not user input +func ParseConfigConnectionIDInsensitively(input string) (*ConfigConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ConfigConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ConfigConnectionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ConfigConnectionId) 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.GatewayName, ok = input.Parsed["gatewayName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "gatewayName", input) + } + + if id.ConfigConnectionName, ok = input.Parsed["configConnectionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "configConnectionName", input) + } + + return nil +} + +// ValidateConfigConnectionID checks that 'input' can be parsed as a Config Connection ID +func ValidateConfigConnectionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseConfigConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Config Connection ID +func (id ConfigConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/gateways/%s/configConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.GatewayName, id.ConfigConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Config Connection ID +func (id ConfigConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticGateways", "gateways", "gateways"), + resourceids.UserSpecifiedSegment("gatewayName", "gatewayValue"), + resourceids.StaticSegment("staticConfigConnections", "configConnections", "configConnections"), + resourceids.UserSpecifiedSegment("configConnectionName", "configConnectionValue"), + } +} + +// String returns a human-readable description of this Config Connection ID +func (id ConfigConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Gateway Name: %q", id.GatewayName), + fmt.Sprintf("Config Connection Name: %q", id.ConfigConnectionName), + } + return fmt.Sprintf("Config Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/id_configconnection_test.go b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/id_configconnection_test.go new file mode 100644 index 00000000000..4fe60ddb59e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/id_configconnection_test.go @@ -0,0 +1,327 @@ +package apigatewayconfigconnection + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ConfigConnectionId{} + +func TestNewConfigConnectionID(t *testing.T) { + id := NewConfigConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayValue", "configConnectionValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.GatewayName != "gatewayValue" { + t.Fatalf("Expected %q but got %q for Segment 'GatewayName'", id.GatewayName, "gatewayValue") + } + + if id.ConfigConnectionName != "configConnectionValue" { + t.Fatalf("Expected %q but got %q for Segment 'ConfigConnectionName'", id.ConfigConnectionName, "configConnectionValue") + } +} + +func TestFormatConfigConnectionID(t *testing.T) { + actual := NewConfigConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayValue", "configConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways/gatewayValue/configConnections/configConnectionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseConfigConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConfigConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways/gatewayValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways/gatewayValue/configConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways/gatewayValue/configConnections/configConnectionValue", + Expected: &ConfigConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GatewayName: "gatewayValue", + ConfigConnectionName: "configConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways/gatewayValue/configConnections/configConnectionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConfigConnectionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GatewayName != v.Expected.GatewayName { + t.Fatalf("Expected %q but got %q for GatewayName", v.Expected.GatewayName, actual.GatewayName) + } + + if actual.ConfigConnectionName != v.Expected.ConfigConnectionName { + t.Fatalf("Expected %q but got %q for ConfigConnectionName", v.Expected.ConfigConnectionName, actual.ConfigConnectionName) + } + + } +} + +func TestParseConfigConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConfigConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/gAtEwAyS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways/gatewayValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/gAtEwAyS/gAtEwAyVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways/gatewayValue/configConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/gAtEwAyS/gAtEwAyVaLuE/cOnFiGcOnNeCtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways/gatewayValue/configConnections/configConnectionValue", + Expected: &ConfigConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GatewayName: "gatewayValue", + ConfigConnectionName: "configConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways/gatewayValue/configConnections/configConnectionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/gAtEwAyS/gAtEwAyVaLuE/cOnFiGcOnNeCtIoNs/cOnFiGcOnNeCtIoNvAlUe", + Expected: &ConfigConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + GatewayName: "gAtEwAyVaLuE", + ConfigConnectionName: "cOnFiGcOnNeCtIoNvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/gAtEwAyS/gAtEwAyVaLuE/cOnFiGcOnNeCtIoNs/cOnFiGcOnNeCtIoNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConfigConnectionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GatewayName != v.Expected.GatewayName { + t.Fatalf("Expected %q but got %q for GatewayName", v.Expected.GatewayName, actual.GatewayName) + } + + if actual.ConfigConnectionName != v.Expected.ConfigConnectionName { + t.Fatalf("Expected %q but got %q for ConfigConnectionName", v.Expected.ConfigConnectionName, actual.ConfigConnectionName) + } + + } +} + +func TestSegmentsForConfigConnectionId(t *testing.T) { + segments := ConfigConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ConfigConnectionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/id_gateway.go b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/id_gateway.go new file mode 100644 index 00000000000..f9e73c43740 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/id_gateway.go @@ -0,0 +1,130 @@ +package apigatewayconfigconnection + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&GatewayId{}) +} + +var _ resourceids.ResourceId = &GatewayId{} + +// GatewayId is a struct representing the Resource ID for a Gateway +type GatewayId struct { + SubscriptionId string + ResourceGroupName string + GatewayName string +} + +// NewGatewayID returns a new GatewayId struct +func NewGatewayID(subscriptionId string, resourceGroupName string, gatewayName string) GatewayId { + return GatewayId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + GatewayName: gatewayName, + } +} + +// ParseGatewayID parses 'input' into a GatewayId +func ParseGatewayID(input string) (*GatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&GatewayId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGatewayIDInsensitively parses 'input' case-insensitively into a GatewayId +// note: this method should only be used for API response data and not user input +func ParseGatewayIDInsensitively(input string) (*GatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&GatewayId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GatewayId) 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.GatewayName, ok = input.Parsed["gatewayName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "gatewayName", input) + } + + return nil +} + +// ValidateGatewayID checks that 'input' can be parsed as a Gateway ID +func ValidateGatewayID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseGatewayID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Gateway ID +func (id GatewayId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/gateways/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.GatewayName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Gateway ID +func (id GatewayId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticGateways", "gateways", "gateways"), + resourceids.UserSpecifiedSegment("gatewayName", "gatewayValue"), + } +} + +// String returns a human-readable description of this Gateway ID +func (id GatewayId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Gateway Name: %q", id.GatewayName), + } + return fmt.Sprintf("Gateway (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/id_gateway_test.go b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/id_gateway_test.go new file mode 100644 index 00000000000..7b0fb483b7b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/id_gateway_test.go @@ -0,0 +1,282 @@ +package apigatewayconfigconnection + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GatewayId{} + +func TestNewGatewayID(t *testing.T) { + id := NewGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.GatewayName != "gatewayValue" { + t.Fatalf("Expected %q but got %q for Segment 'GatewayName'", id.GatewayName, "gatewayValue") + } +} + +func TestFormatGatewayID(t *testing.T) { + actual := NewGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways/gatewayValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGatewayID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways/gatewayValue", + Expected: &GatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GatewayName: "gatewayValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways/gatewayValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGatewayID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GatewayName != v.Expected.GatewayName { + t.Fatalf("Expected %q but got %q for GatewayName", v.Expected.GatewayName, actual.GatewayName) + } + + } +} + +func TestParseGatewayIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/gAtEwAyS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways/gatewayValue", + Expected: &GatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GatewayName: "gatewayValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways/gatewayValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/gAtEwAyS/gAtEwAyVaLuE", + Expected: &GatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + GatewayName: "gAtEwAyVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/gAtEwAyS/gAtEwAyVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGatewayIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GatewayName != v.Expected.GatewayName { + t.Fatalf("Expected %q but got %q for GatewayName", v.Expected.GatewayName, actual.GatewayName) + } + + } +} + +func TestSegmentsForGatewayId(t *testing.T) { + segments := GatewayId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GatewayId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/method_createorupdate.go new file mode 100644 index 00000000000..f0f02128c59 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/method_createorupdate.go @@ -0,0 +1,75 @@ +package apigatewayconfigconnection + +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 *ApiManagementGatewayConfigConnectionResource +} + +// CreateOrUpdate ... +func (c ApiGatewayConfigConnectionClient) CreateOrUpdate(ctx context.Context, id ConfigConnectionId, input ApiManagementGatewayConfigConnectionResource) (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 ApiGatewayConfigConnectionClient) CreateOrUpdateThenPoll(ctx context.Context, id ConfigConnectionId, input ApiManagementGatewayConfigConnectionResource) 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/apimanagement/2024-05-01/apigatewayconfigconnection/method_delete.go b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/method_delete.go new file mode 100644 index 00000000000..1fd0e2e9dad --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/method_delete.go @@ -0,0 +1,98 @@ +package apigatewayconfigconnection + +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 +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c ApiGatewayConfigConnectionClient) Delete(ctx context.Context, id ConfigConnectionId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + 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 ApiGatewayConfigConnectionClient) DeleteThenPoll(ctx context.Context, id ConfigConnectionId, options DeleteOperationOptions) error { + result, err := c.Delete(ctx, id, options) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/method_get.go b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/method_get.go new file mode 100644 index 00000000000..66a57cc0234 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/method_get.go @@ -0,0 +1,54 @@ +package apigatewayconfigconnection + +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 *ApiManagementGatewayConfigConnectionResource +} + +// Get ... +func (c ApiGatewayConfigConnectionClient) Get(ctx context.Context, id ConfigConnectionId) (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 ApiManagementGatewayConfigConnectionResource + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/method_listbygateway.go b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/method_listbygateway.go new file mode 100644 index 00000000000..7b51804b94a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/method_listbygateway.go @@ -0,0 +1,105 @@ +package apigatewayconfigconnection + +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 ListByGatewayOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ApiManagementGatewayConfigConnectionResource +} + +type ListByGatewayCompleteResult struct { + LatestHttpResponse *http.Response + Items []ApiManagementGatewayConfigConnectionResource +} + +type ListByGatewayCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByGatewayCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByGateway ... +func (c ApiGatewayConfigConnectionClient) ListByGateway(ctx context.Context, id GatewayId) (result ListByGatewayOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByGatewayCustomPager{}, + Path: fmt.Sprintf("%s/configConnections", 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 *[]ApiManagementGatewayConfigConnectionResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByGatewayComplete retrieves all the results into a single object +func (c ApiGatewayConfigConnectionClient) ListByGatewayComplete(ctx context.Context, id GatewayId) (ListByGatewayCompleteResult, error) { + return c.ListByGatewayCompleteMatchingPredicate(ctx, id, ApiManagementGatewayConfigConnectionResourceOperationPredicate{}) +} + +// ListByGatewayCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiGatewayConfigConnectionClient) ListByGatewayCompleteMatchingPredicate(ctx context.Context, id GatewayId, predicate ApiManagementGatewayConfigConnectionResourceOperationPredicate) (result ListByGatewayCompleteResult, err error) { + items := make([]ApiManagementGatewayConfigConnectionResource, 0) + + resp, err := c.ListByGateway(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByGatewayCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/model_apimanagementgatewayconfigconnectionresource.go b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/model_apimanagementgatewayconfigconnectionresource.go new file mode 100644 index 00000000000..694aa133baf --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/model_apimanagementgatewayconfigconnectionresource.go @@ -0,0 +1,12 @@ +package apigatewayconfigconnection + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementGatewayConfigConnectionResource struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties GatewayConfigConnectionBaseProperties `json:"properties"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/model_gatewayconfigconnectionbaseproperties.go b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/model_gatewayconfigconnectionbaseproperties.go new file mode 100644 index 00000000000..e35df6be622 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/model_gatewayconfigconnectionbaseproperties.go @@ -0,0 +1,11 @@ +package apigatewayconfigconnection + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewayConfigConnectionBaseProperties struct { + DefaultHostname *string `json:"defaultHostname,omitempty"` + Hostnames *[]string `json:"hostnames,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + SourceId *string `json:"sourceId,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/predicates.go b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/predicates.go new file mode 100644 index 00000000000..3847dd9c6e6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/predicates.go @@ -0,0 +1,32 @@ +package apigatewayconfigconnection + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementGatewayConfigConnectionResourceOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p ApiManagementGatewayConfigConnectionResourceOperationPredicate) Matches(input ApiManagementGatewayConfigConnectionResource) bool { + + if p.Etag != nil && (input.Etag == nil || *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.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/apimanagement/2024-05-01/apigatewayconfigconnection/version.go b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/version.go new file mode 100644 index 00000000000..0f073d11f2c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection/version.go @@ -0,0 +1,12 @@ +package apigatewayconfigconnection + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apigatewayconfigconnection/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissue/README.md b/resource-manager/apimanagement/2024-05-01/apiissue/README.md new file mode 100644 index 00000000000..2c34c64f24d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissue/README.md @@ -0,0 +1,127 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apiissue` Documentation + +The `apiissue` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apiissue" +``` + + +### Client Initialization + +```go +client := apiissue.NewApiIssueClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiIssueClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := apiissue.NewApiIssueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue") + +payload := apiissue.IssueContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, apiissue.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiIssueClient.Delete` + +```go +ctx := context.TODO() +id := apiissue.NewApiIssueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue") + +read, err := client.Delete(ctx, id, apiissue.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiIssueClient.Get` + +```go +ctx := context.TODO() +id := apiissue.NewApiIssueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue") + +read, err := client.Get(ctx, id, apiissue.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiIssueClient.GetEntityTag` + +```go +ctx := context.TODO() +id := apiissue.NewApiIssueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiIssueClient.ListByService` + +```go +ctx := context.TODO() +id := apiissue.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +// alternatively `client.ListByService(ctx, id, apiissue.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, apiissue.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ApiIssueClient.Update` + +```go +ctx := context.TODO() +id := apiissue.NewApiIssueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue") + +payload := apiissue.IssueUpdateContract{ + // ... +} + + +read, err := client.Update(ctx, id, payload, apiissue.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/apiissue/client.go b/resource-manager/apimanagement/2024-05-01/apiissue/client.go new file mode 100644 index 00000000000..33f2a33d684 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissue/client.go @@ -0,0 +1,26 @@ +package apiissue + +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 ApiIssueClient struct { + Client *resourcemanager.Client +} + +func NewApiIssueClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiIssueClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apiissue", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiIssueClient: %+v", err) + } + + return &ApiIssueClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissue/constants.go b/resource-manager/apimanagement/2024-05-01/apiissue/constants.go new file mode 100644 index 00000000000..16888d5e064 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissue/constants.go @@ -0,0 +1,60 @@ +package apiissue + +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 State string + +const ( + StateClosed State = "closed" + StateOpen State = "open" + StateProposed State = "proposed" + StateRemoved State = "removed" + StateResolved State = "resolved" +) + +func PossibleValuesForState() []string { + return []string{ + string(StateClosed), + string(StateOpen), + string(StateProposed), + string(StateRemoved), + string(StateResolved), + } +} + +func (s *State) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseState(input string) (*State, error) { + vals := map[string]State{ + "closed": StateClosed, + "open": StateOpen, + "proposed": StateProposed, + "removed": StateRemoved, + "resolved": StateResolved, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := State(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissue/id_api.go b/resource-manager/apimanagement/2024-05-01/apiissue/id_api.go new file mode 100644 index 00000000000..f42ff72ff21 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissue/id_api.go @@ -0,0 +1,139 @@ +package apiissue + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiId{}) +} + +var _ resourceids.ResourceId = &ApiId{} + +// ApiId is a struct representing the Resource ID for a Api +type ApiId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string +} + +// NewApiID returns a new ApiId struct +func NewApiID(subscriptionId string, resourceGroupName string, serviceName string, apiId string) ApiId { + return ApiId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + } +} + +// ParseApiID parses 'input' into a ApiId +func ParseApiID(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiIDInsensitively parses 'input' case-insensitively into a ApiId +// note: this method should only be used for API response data and not user input +func ParseApiIDInsensitively(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + return nil +} + +// ValidateApiID checks that 'input' can be parsed as a Api ID +func ValidateApiID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api ID +func (id ApiId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api ID +func (id ApiId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + } +} + +// String returns a human-readable description of this Api ID +func (id ApiId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + } + return fmt.Sprintf("Api (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissue/id_api_test.go b/resource-manager/apimanagement/2024-05-01/apiissue/id_api_test.go new file mode 100644 index 00000000000..0276a381456 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissue/id_api_test.go @@ -0,0 +1,327 @@ +package apiissue + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiId{} + +func TestNewApiID(t *testing.T) { + id := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } +} + +func TestFormatApiID(t *testing.T) { + actual := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestParseApiIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestSegmentsForApiId(t *testing.T) { + segments := ApiId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissue/id_apiissue.go b/resource-manager/apimanagement/2024-05-01/apiissue/id_apiissue.go new file mode 100644 index 00000000000..7b13fff0230 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissue/id_apiissue.go @@ -0,0 +1,148 @@ +package apiissue + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiIssueId{}) +} + +var _ resourceids.ResourceId = &ApiIssueId{} + +// ApiIssueId is a struct representing the Resource ID for a Api Issue +type ApiIssueId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string + IssueId string +} + +// NewApiIssueID returns a new ApiIssueId struct +func NewApiIssueID(subscriptionId string, resourceGroupName string, serviceName string, apiId string, issueId string) ApiIssueId { + return ApiIssueId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + IssueId: issueId, + } +} + +// ParseApiIssueID parses 'input' into a ApiIssueId +func ParseApiIssueID(input string) (*ApiIssueId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiIssueId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiIssueId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiIssueIDInsensitively parses 'input' case-insensitively into a ApiIssueId +// note: this method should only be used for API response data and not user input +func ParseApiIssueIDInsensitively(input string) (*ApiIssueId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiIssueId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiIssueId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiIssueId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + if id.IssueId, ok = input.Parsed["issueId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "issueId", input) + } + + return nil +} + +// ValidateApiIssueID checks that 'input' can be parsed as a Api Issue ID +func ValidateApiIssueID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiIssueID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api Issue ID +func (id ApiIssueId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s/issues/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId, id.IssueId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api Issue ID +func (id ApiIssueId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + resourceids.StaticSegment("staticIssues", "issues", "issues"), + resourceids.UserSpecifiedSegment("issueId", "issueIdValue"), + } +} + +// String returns a human-readable description of this Api Issue ID +func (id ApiIssueId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + fmt.Sprintf("Issue: %q", id.IssueId), + } + return fmt.Sprintf("Api Issue (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissue/id_apiissue_test.go b/resource-manager/apimanagement/2024-05-01/apiissue/id_apiissue_test.go new file mode 100644 index 00000000000..3afc6f01178 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissue/id_apiissue_test.go @@ -0,0 +1,372 @@ +package apiissue + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiIssueId{} + +func TestNewApiIssueID(t *testing.T) { + id := NewApiIssueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } + + if id.IssueId != "issueIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'IssueId'", id.IssueId, "issueIdValue") + } +} + +func TestFormatApiIssueID(t *testing.T) { + actual := NewApiIssueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiIssueID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiIssueId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue", + Expected: &ApiIssueId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + IssueId: "issueIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiIssueID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.IssueId != v.Expected.IssueId { + t.Fatalf("Expected %q but got %q for IssueId", v.Expected.IssueId, actual.IssueId) + } + + } +} + +func TestParseApiIssueIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiIssueId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/iSsUeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue", + Expected: &ApiIssueId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + IssueId: "issueIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/iSsUeS/iSsUeIdVaLuE", + Expected: &ApiIssueId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + IssueId: "iSsUeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/iSsUeS/iSsUeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiIssueIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.IssueId != v.Expected.IssueId { + t.Fatalf("Expected %q but got %q for IssueId", v.Expected.IssueId, actual.IssueId) + } + + } +} + +func TestSegmentsForApiIssueId(t *testing.T) { + segments := ApiIssueId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiIssueId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissue/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/apiissue/method_createorupdate.go new file mode 100644 index 00000000000..2c843315ed6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissue/method_createorupdate.go @@ -0,0 +1,88 @@ +package apiissue + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IssueContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c ApiIssueClient) CreateOrUpdate(ctx context.Context, id ApiIssueId, input IssueContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 IssueContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissue/method_delete.go b/resource-manager/apimanagement/2024-05-01/apiissue/method_delete.go new file mode 100644 index 00000000000..c51a70bf93d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissue/method_delete.go @@ -0,0 +1,76 @@ +package apiissue + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c ApiIssueClient) Delete(ctx context.Context, id ApiIssueId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissue/method_get.go b/resource-manager/apimanagement/2024-05-01/apiissue/method_get.go new file mode 100644 index 00000000000..a4f0ff0be8a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissue/method_get.go @@ -0,0 +1,83 @@ +package apiissue + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IssueContract +} + +type GetOperationOptions struct { + ExpandCommentsAttachments *bool +} + +func DefaultGetOperationOptions() GetOperationOptions { + return GetOperationOptions{} +} + +func (o GetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o GetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o GetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.ExpandCommentsAttachments != nil { + out.Append("expandCommentsAttachments", fmt.Sprintf("%v", *o.ExpandCommentsAttachments)) + } + return &out +} + +// Get ... +func (c ApiIssueClient) Get(ctx context.Context, id ApiIssueId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + 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 IssueContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissue/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/apiissue/method_getentitytag.go new file mode 100644 index 00000000000..fa22e539b24 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissue/method_getentitytag.go @@ -0,0 +1,46 @@ +package apiissue + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c ApiIssueClient) GetEntityTag(ctx context.Context, id ApiIssueId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissue/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/apiissue/method_listbyservice.go new file mode 100644 index 00000000000..314d87e9b6e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissue/method_listbyservice.go @@ -0,0 +1,145 @@ +package apiissue + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]IssueContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []IssueContract +} + +type ListByServiceOperationOptions struct { + ExpandCommentsAttachments *bool + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.ExpandCommentsAttachments != nil { + out.Append("expandCommentsAttachments", fmt.Sprintf("%v", *o.ExpandCommentsAttachments)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c ApiIssueClient) ListByService(ctx context.Context, id ApiId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/issues", 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 *[]IssueContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c ApiIssueClient) ListByServiceComplete(ctx context.Context, id ApiId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, IssueContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiIssueClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ApiId, options ListByServiceOperationOptions, predicate IssueContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]IssueContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissue/method_update.go b/resource-manager/apimanagement/2024-05-01/apiissue/method_update.go new file mode 100644 index 00000000000..5db5804bbb2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissue/method_update.go @@ -0,0 +1,87 @@ +package apiissue + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IssueContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c ApiIssueClient) Update(ctx context.Context, id ApiIssueId, input IssueUpdateContract, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 IssueContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissue/model_issuecontract.go b/resource-manager/apimanagement/2024-05-01/apiissue/model_issuecontract.go new file mode 100644 index 00000000000..6d6948d3605 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissue/model_issuecontract.go @@ -0,0 +1,11 @@ +package apiissue + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IssueContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *IssueContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissue/model_issuecontractproperties.go b/resource-manager/apimanagement/2024-05-01/apiissue/model_issuecontractproperties.go new file mode 100644 index 00000000000..d96401f4701 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissue/model_issuecontractproperties.go @@ -0,0 +1,31 @@ +package apiissue + +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 IssueContractProperties struct { + ApiId *string `json:"apiId,omitempty"` + CreatedDate *string `json:"createdDate,omitempty"` + Description string `json:"description"` + State *State `json:"state,omitempty"` + Title string `json:"title"` + UserId string `json:"userId"` +} + +func (o *IssueContractProperties) GetCreatedDateAsTime() (*time.Time, error) { + if o.CreatedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *IssueContractProperties) SetCreatedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedDate = &formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissue/model_issueupdatecontract.go b/resource-manager/apimanagement/2024-05-01/apiissue/model_issueupdatecontract.go new file mode 100644 index 00000000000..98537d59305 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissue/model_issueupdatecontract.go @@ -0,0 +1,8 @@ +package apiissue + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IssueUpdateContract struct { + Properties *IssueUpdateContractProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissue/model_issueupdatecontractproperties.go b/resource-manager/apimanagement/2024-05-01/apiissue/model_issueupdatecontractproperties.go new file mode 100644 index 00000000000..d54a5467c52 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissue/model_issueupdatecontractproperties.go @@ -0,0 +1,31 @@ +package apiissue + +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 IssueUpdateContractProperties struct { + ApiId *string `json:"apiId,omitempty"` + CreatedDate *string `json:"createdDate,omitempty"` + Description *string `json:"description,omitempty"` + State *State `json:"state,omitempty"` + Title *string `json:"title,omitempty"` + UserId *string `json:"userId,omitempty"` +} + +func (o *IssueUpdateContractProperties) GetCreatedDateAsTime() (*time.Time, error) { + if o.CreatedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *IssueUpdateContractProperties) SetCreatedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedDate = &formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissue/predicates.go b/resource-manager/apimanagement/2024-05-01/apiissue/predicates.go new file mode 100644 index 00000000000..9b2707f32ce --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissue/predicates.go @@ -0,0 +1,27 @@ +package apiissue + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IssueContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p IssueContractOperationPredicate) Matches(input IssueContract) 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/apimanagement/2024-05-01/apiissue/version.go b/resource-manager/apimanagement/2024-05-01/apiissue/version.go new file mode 100644 index 00000000000..d1c701cf8c2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissue/version.go @@ -0,0 +1,12 @@ +package apiissue + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apiissue/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissueattachment/README.md b/resource-manager/apimanagement/2024-05-01/apiissueattachment/README.md new file mode 100644 index 00000000000..d2218a5e07a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissueattachment/README.md @@ -0,0 +1,106 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apiissueattachment` Documentation + +The `apiissueattachment` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apiissueattachment" +``` + + +### Client Initialization + +```go +client := apiissueattachment.NewApiIssueAttachmentClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiIssueAttachmentClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := apiissueattachment.NewAttachmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue", "attachmentIdValue") + +payload := apiissueattachment.IssueAttachmentContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, apiissueattachment.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiIssueAttachmentClient.Delete` + +```go +ctx := context.TODO() +id := apiissueattachment.NewAttachmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue", "attachmentIdValue") + +read, err := client.Delete(ctx, id, apiissueattachment.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiIssueAttachmentClient.Get` + +```go +ctx := context.TODO() +id := apiissueattachment.NewAttachmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue", "attachmentIdValue") + +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: `ApiIssueAttachmentClient.GetEntityTag` + +```go +ctx := context.TODO() +id := apiissueattachment.NewAttachmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue", "attachmentIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiIssueAttachmentClient.ListByService` + +```go +ctx := context.TODO() +id := apiissueattachment.NewApiIssueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue") + +// alternatively `client.ListByService(ctx, id, apiissueattachment.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, apiissueattachment.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/apiissueattachment/client.go b/resource-manager/apimanagement/2024-05-01/apiissueattachment/client.go new file mode 100644 index 00000000000..84b276260e3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissueattachment/client.go @@ -0,0 +1,26 @@ +package apiissueattachment + +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 ApiIssueAttachmentClient struct { + Client *resourcemanager.Client +} + +func NewApiIssueAttachmentClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiIssueAttachmentClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apiissueattachment", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiIssueAttachmentClient: %+v", err) + } + + return &ApiIssueAttachmentClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissueattachment/id_apiissue.go b/resource-manager/apimanagement/2024-05-01/apiissueattachment/id_apiissue.go new file mode 100644 index 00000000000..b77d45c0fdb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissueattachment/id_apiissue.go @@ -0,0 +1,148 @@ +package apiissueattachment + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiIssueId{}) +} + +var _ resourceids.ResourceId = &ApiIssueId{} + +// ApiIssueId is a struct representing the Resource ID for a Api Issue +type ApiIssueId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string + IssueId string +} + +// NewApiIssueID returns a new ApiIssueId struct +func NewApiIssueID(subscriptionId string, resourceGroupName string, serviceName string, apiId string, issueId string) ApiIssueId { + return ApiIssueId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + IssueId: issueId, + } +} + +// ParseApiIssueID parses 'input' into a ApiIssueId +func ParseApiIssueID(input string) (*ApiIssueId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiIssueId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiIssueId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiIssueIDInsensitively parses 'input' case-insensitively into a ApiIssueId +// note: this method should only be used for API response data and not user input +func ParseApiIssueIDInsensitively(input string) (*ApiIssueId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiIssueId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiIssueId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiIssueId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + if id.IssueId, ok = input.Parsed["issueId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "issueId", input) + } + + return nil +} + +// ValidateApiIssueID checks that 'input' can be parsed as a Api Issue ID +func ValidateApiIssueID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiIssueID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api Issue ID +func (id ApiIssueId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s/issues/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId, id.IssueId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api Issue ID +func (id ApiIssueId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + resourceids.StaticSegment("staticIssues", "issues", "issues"), + resourceids.UserSpecifiedSegment("issueId", "issueIdValue"), + } +} + +// String returns a human-readable description of this Api Issue ID +func (id ApiIssueId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + fmt.Sprintf("Issue: %q", id.IssueId), + } + return fmt.Sprintf("Api Issue (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissueattachment/id_apiissue_test.go b/resource-manager/apimanagement/2024-05-01/apiissueattachment/id_apiissue_test.go new file mode 100644 index 00000000000..b2411fecf81 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissueattachment/id_apiissue_test.go @@ -0,0 +1,372 @@ +package apiissueattachment + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiIssueId{} + +func TestNewApiIssueID(t *testing.T) { + id := NewApiIssueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } + + if id.IssueId != "issueIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'IssueId'", id.IssueId, "issueIdValue") + } +} + +func TestFormatApiIssueID(t *testing.T) { + actual := NewApiIssueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiIssueID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiIssueId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue", + Expected: &ApiIssueId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + IssueId: "issueIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiIssueID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.IssueId != v.Expected.IssueId { + t.Fatalf("Expected %q but got %q for IssueId", v.Expected.IssueId, actual.IssueId) + } + + } +} + +func TestParseApiIssueIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiIssueId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/iSsUeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue", + Expected: &ApiIssueId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + IssueId: "issueIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/iSsUeS/iSsUeIdVaLuE", + Expected: &ApiIssueId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + IssueId: "iSsUeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/iSsUeS/iSsUeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiIssueIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.IssueId != v.Expected.IssueId { + t.Fatalf("Expected %q but got %q for IssueId", v.Expected.IssueId, actual.IssueId) + } + + } +} + +func TestSegmentsForApiIssueId(t *testing.T) { + segments := ApiIssueId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiIssueId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissueattachment/id_attachment.go b/resource-manager/apimanagement/2024-05-01/apiissueattachment/id_attachment.go new file mode 100644 index 00000000000..c57aa82518a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissueattachment/id_attachment.go @@ -0,0 +1,157 @@ +package apiissueattachment + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AttachmentId{}) +} + +var _ resourceids.ResourceId = &AttachmentId{} + +// AttachmentId is a struct representing the Resource ID for a Attachment +type AttachmentId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string + IssueId string + AttachmentId string +} + +// NewAttachmentID returns a new AttachmentId struct +func NewAttachmentID(subscriptionId string, resourceGroupName string, serviceName string, apiId string, issueId string, attachmentId string) AttachmentId { + return AttachmentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + IssueId: issueId, + AttachmentId: attachmentId, + } +} + +// ParseAttachmentID parses 'input' into a AttachmentId +func ParseAttachmentID(input string) (*AttachmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&AttachmentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AttachmentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAttachmentIDInsensitively parses 'input' case-insensitively into a AttachmentId +// note: this method should only be used for API response data and not user input +func ParseAttachmentIDInsensitively(input string) (*AttachmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&AttachmentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AttachmentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AttachmentId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + if id.IssueId, ok = input.Parsed["issueId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "issueId", input) + } + + if id.AttachmentId, ok = input.Parsed["attachmentId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "attachmentId", input) + } + + return nil +} + +// ValidateAttachmentID checks that 'input' can be parsed as a Attachment ID +func ValidateAttachmentID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseAttachmentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Attachment ID +func (id AttachmentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s/issues/%s/attachments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId, id.IssueId, id.AttachmentId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Attachment ID +func (id AttachmentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + resourceids.StaticSegment("staticIssues", "issues", "issues"), + resourceids.UserSpecifiedSegment("issueId", "issueIdValue"), + resourceids.StaticSegment("staticAttachments", "attachments", "attachments"), + resourceids.UserSpecifiedSegment("attachmentId", "attachmentIdValue"), + } +} + +// String returns a human-readable description of this Attachment ID +func (id AttachmentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + fmt.Sprintf("Issue: %q", id.IssueId), + fmt.Sprintf("Attachment: %q", id.AttachmentId), + } + return fmt.Sprintf("Attachment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissueattachment/id_attachment_test.go b/resource-manager/apimanagement/2024-05-01/apiissueattachment/id_attachment_test.go new file mode 100644 index 00000000000..07697c3bc90 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissueattachment/id_attachment_test.go @@ -0,0 +1,417 @@ +package apiissueattachment + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AttachmentId{} + +func TestNewAttachmentID(t *testing.T) { + id := NewAttachmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue", "attachmentIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } + + if id.IssueId != "issueIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'IssueId'", id.IssueId, "issueIdValue") + } + + if id.AttachmentId != "attachmentIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'AttachmentId'", id.AttachmentId, "attachmentIdValue") + } +} + +func TestFormatAttachmentID(t *testing.T) { + actual := NewAttachmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue", "attachmentIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue/attachments/attachmentIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAttachmentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AttachmentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue/attachments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue/attachments/attachmentIdValue", + Expected: &AttachmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + IssueId: "issueIdValue", + AttachmentId: "attachmentIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue/attachments/attachmentIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAttachmentID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.IssueId != v.Expected.IssueId { + t.Fatalf("Expected %q but got %q for IssueId", v.Expected.IssueId, actual.IssueId) + } + + if actual.AttachmentId != v.Expected.AttachmentId { + t.Fatalf("Expected %q but got %q for AttachmentId", v.Expected.AttachmentId, actual.AttachmentId) + } + + } +} + +func TestParseAttachmentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AttachmentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/iSsUeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/iSsUeS/iSsUeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue/attachments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/iSsUeS/iSsUeIdVaLuE/aTtAcHmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue/attachments/attachmentIdValue", + Expected: &AttachmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + IssueId: "issueIdValue", + AttachmentId: "attachmentIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue/attachments/attachmentIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/iSsUeS/iSsUeIdVaLuE/aTtAcHmEnTs/aTtAcHmEnTiDvAlUe", + Expected: &AttachmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + IssueId: "iSsUeIdVaLuE", + AttachmentId: "aTtAcHmEnTiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/iSsUeS/iSsUeIdVaLuE/aTtAcHmEnTs/aTtAcHmEnTiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAttachmentIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.IssueId != v.Expected.IssueId { + t.Fatalf("Expected %q but got %q for IssueId", v.Expected.IssueId, actual.IssueId) + } + + if actual.AttachmentId != v.Expected.AttachmentId { + t.Fatalf("Expected %q but got %q for AttachmentId", v.Expected.AttachmentId, actual.AttachmentId) + } + + } +} + +func TestSegmentsForAttachmentId(t *testing.T) { + segments := AttachmentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AttachmentId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissueattachment/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/apiissueattachment/method_createorupdate.go new file mode 100644 index 00000000000..a44575c4ae0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissueattachment/method_createorupdate.go @@ -0,0 +1,88 @@ +package apiissueattachment + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IssueAttachmentContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c ApiIssueAttachmentClient) CreateOrUpdate(ctx context.Context, id AttachmentId, input IssueAttachmentContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 IssueAttachmentContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissueattachment/method_delete.go b/resource-manager/apimanagement/2024-05-01/apiissueattachment/method_delete.go new file mode 100644 index 00000000000..867e45b1ffc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissueattachment/method_delete.go @@ -0,0 +1,76 @@ +package apiissueattachment + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c ApiIssueAttachmentClient) Delete(ctx context.Context, id AttachmentId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissueattachment/method_get.go b/resource-manager/apimanagement/2024-05-01/apiissueattachment/method_get.go new file mode 100644 index 00000000000..f544ca53f2b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissueattachment/method_get.go @@ -0,0 +1,54 @@ +package apiissueattachment + +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 *IssueAttachmentContract +} + +// Get ... +func (c ApiIssueAttachmentClient) Get(ctx context.Context, id AttachmentId) (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 IssueAttachmentContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissueattachment/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/apiissueattachment/method_getentitytag.go new file mode 100644 index 00000000000..417b3e0b9bd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissueattachment/method_getentitytag.go @@ -0,0 +1,46 @@ +package apiissueattachment + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c ApiIssueAttachmentClient) GetEntityTag(ctx context.Context, id AttachmentId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissueattachment/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/apiissueattachment/method_listbyservice.go new file mode 100644 index 00000000000..7e2162ab2a9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissueattachment/method_listbyservice.go @@ -0,0 +1,141 @@ +package apiissueattachment + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]IssueAttachmentContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []IssueAttachmentContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c ApiIssueAttachmentClient) ListByService(ctx context.Context, id ApiIssueId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/attachments", 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 *[]IssueAttachmentContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c ApiIssueAttachmentClient) ListByServiceComplete(ctx context.Context, id ApiIssueId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, IssueAttachmentContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiIssueAttachmentClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ApiIssueId, options ListByServiceOperationOptions, predicate IssueAttachmentContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]IssueAttachmentContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissueattachment/model_issueattachmentcontract.go b/resource-manager/apimanagement/2024-05-01/apiissueattachment/model_issueattachmentcontract.go new file mode 100644 index 00000000000..87dbfd6d6c2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissueattachment/model_issueattachmentcontract.go @@ -0,0 +1,11 @@ +package apiissueattachment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IssueAttachmentContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *IssueAttachmentContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissueattachment/model_issueattachmentcontractproperties.go b/resource-manager/apimanagement/2024-05-01/apiissueattachment/model_issueattachmentcontractproperties.go new file mode 100644 index 00000000000..bba7c579db0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissueattachment/model_issueattachmentcontractproperties.go @@ -0,0 +1,10 @@ +package apiissueattachment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IssueAttachmentContractProperties struct { + Content string `json:"content"` + ContentFormat string `json:"contentFormat"` + Title string `json:"title"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissueattachment/predicates.go b/resource-manager/apimanagement/2024-05-01/apiissueattachment/predicates.go new file mode 100644 index 00000000000..9ad56fa6d65 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissueattachment/predicates.go @@ -0,0 +1,27 @@ +package apiissueattachment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IssueAttachmentContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p IssueAttachmentContractOperationPredicate) Matches(input IssueAttachmentContract) 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/apimanagement/2024-05-01/apiissueattachment/version.go b/resource-manager/apimanagement/2024-05-01/apiissueattachment/version.go new file mode 100644 index 00000000000..b09afb7a70c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissueattachment/version.go @@ -0,0 +1,12 @@ +package apiissueattachment + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apiissueattachment/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissuecomment/README.md b/resource-manager/apimanagement/2024-05-01/apiissuecomment/README.md new file mode 100644 index 00000000000..ff780de7968 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissuecomment/README.md @@ -0,0 +1,106 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apiissuecomment` Documentation + +The `apiissuecomment` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apiissuecomment" +``` + + +### Client Initialization + +```go +client := apiissuecomment.NewApiIssueCommentClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiIssueCommentClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := apiissuecomment.NewCommentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue", "commentIdValue") + +payload := apiissuecomment.IssueCommentContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, apiissuecomment.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiIssueCommentClient.Delete` + +```go +ctx := context.TODO() +id := apiissuecomment.NewCommentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue", "commentIdValue") + +read, err := client.Delete(ctx, id, apiissuecomment.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiIssueCommentClient.Get` + +```go +ctx := context.TODO() +id := apiissuecomment.NewCommentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue", "commentIdValue") + +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: `ApiIssueCommentClient.GetEntityTag` + +```go +ctx := context.TODO() +id := apiissuecomment.NewCommentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue", "commentIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiIssueCommentClient.ListByService` + +```go +ctx := context.TODO() +id := apiissuecomment.NewApiIssueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue") + +// alternatively `client.ListByService(ctx, id, apiissuecomment.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, apiissuecomment.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/apiissuecomment/client.go b/resource-manager/apimanagement/2024-05-01/apiissuecomment/client.go new file mode 100644 index 00000000000..22377af4fed --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissuecomment/client.go @@ -0,0 +1,26 @@ +package apiissuecomment + +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 ApiIssueCommentClient struct { + Client *resourcemanager.Client +} + +func NewApiIssueCommentClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiIssueCommentClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apiissuecomment", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiIssueCommentClient: %+v", err) + } + + return &ApiIssueCommentClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissuecomment/id_apiissue.go b/resource-manager/apimanagement/2024-05-01/apiissuecomment/id_apiissue.go new file mode 100644 index 00000000000..dff007275dc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissuecomment/id_apiissue.go @@ -0,0 +1,148 @@ +package apiissuecomment + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiIssueId{}) +} + +var _ resourceids.ResourceId = &ApiIssueId{} + +// ApiIssueId is a struct representing the Resource ID for a Api Issue +type ApiIssueId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string + IssueId string +} + +// NewApiIssueID returns a new ApiIssueId struct +func NewApiIssueID(subscriptionId string, resourceGroupName string, serviceName string, apiId string, issueId string) ApiIssueId { + return ApiIssueId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + IssueId: issueId, + } +} + +// ParseApiIssueID parses 'input' into a ApiIssueId +func ParseApiIssueID(input string) (*ApiIssueId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiIssueId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiIssueId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiIssueIDInsensitively parses 'input' case-insensitively into a ApiIssueId +// note: this method should only be used for API response data and not user input +func ParseApiIssueIDInsensitively(input string) (*ApiIssueId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiIssueId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiIssueId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiIssueId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + if id.IssueId, ok = input.Parsed["issueId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "issueId", input) + } + + return nil +} + +// ValidateApiIssueID checks that 'input' can be parsed as a Api Issue ID +func ValidateApiIssueID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiIssueID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api Issue ID +func (id ApiIssueId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s/issues/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId, id.IssueId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api Issue ID +func (id ApiIssueId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + resourceids.StaticSegment("staticIssues", "issues", "issues"), + resourceids.UserSpecifiedSegment("issueId", "issueIdValue"), + } +} + +// String returns a human-readable description of this Api Issue ID +func (id ApiIssueId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + fmt.Sprintf("Issue: %q", id.IssueId), + } + return fmt.Sprintf("Api Issue (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissuecomment/id_apiissue_test.go b/resource-manager/apimanagement/2024-05-01/apiissuecomment/id_apiissue_test.go new file mode 100644 index 00000000000..9adf77538b5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissuecomment/id_apiissue_test.go @@ -0,0 +1,372 @@ +package apiissuecomment + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiIssueId{} + +func TestNewApiIssueID(t *testing.T) { + id := NewApiIssueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } + + if id.IssueId != "issueIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'IssueId'", id.IssueId, "issueIdValue") + } +} + +func TestFormatApiIssueID(t *testing.T) { + actual := NewApiIssueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiIssueID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiIssueId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue", + Expected: &ApiIssueId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + IssueId: "issueIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiIssueID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.IssueId != v.Expected.IssueId { + t.Fatalf("Expected %q but got %q for IssueId", v.Expected.IssueId, actual.IssueId) + } + + } +} + +func TestParseApiIssueIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiIssueId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/iSsUeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue", + Expected: &ApiIssueId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + IssueId: "issueIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/iSsUeS/iSsUeIdVaLuE", + Expected: &ApiIssueId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + IssueId: "iSsUeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/iSsUeS/iSsUeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiIssueIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.IssueId != v.Expected.IssueId { + t.Fatalf("Expected %q but got %q for IssueId", v.Expected.IssueId, actual.IssueId) + } + + } +} + +func TestSegmentsForApiIssueId(t *testing.T) { + segments := ApiIssueId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiIssueId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissuecomment/id_comment.go b/resource-manager/apimanagement/2024-05-01/apiissuecomment/id_comment.go new file mode 100644 index 00000000000..46ee496fa82 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissuecomment/id_comment.go @@ -0,0 +1,157 @@ +package apiissuecomment + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&CommentId{}) +} + +var _ resourceids.ResourceId = &CommentId{} + +// CommentId is a struct representing the Resource ID for a Comment +type CommentId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string + IssueId string + CommentId string +} + +// NewCommentID returns a new CommentId struct +func NewCommentID(subscriptionId string, resourceGroupName string, serviceName string, apiId string, issueId string, commentId string) CommentId { + return CommentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + IssueId: issueId, + CommentId: commentId, + } +} + +// ParseCommentID parses 'input' into a CommentId +func ParseCommentID(input string) (*CommentId, error) { + parser := resourceids.NewParserFromResourceIdType(&CommentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CommentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseCommentIDInsensitively parses 'input' case-insensitively into a CommentId +// note: this method should only be used for API response data and not user input +func ParseCommentIDInsensitively(input string) (*CommentId, error) { + parser := resourceids.NewParserFromResourceIdType(&CommentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CommentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *CommentId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + if id.IssueId, ok = input.Parsed["issueId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "issueId", input) + } + + if id.CommentId, ok = input.Parsed["commentId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "commentId", input) + } + + return nil +} + +// ValidateCommentID checks that 'input' can be parsed as a Comment ID +func ValidateCommentID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseCommentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Comment ID +func (id CommentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s/issues/%s/comments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId, id.IssueId, id.CommentId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Comment ID +func (id CommentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + resourceids.StaticSegment("staticIssues", "issues", "issues"), + resourceids.UserSpecifiedSegment("issueId", "issueIdValue"), + resourceids.StaticSegment("staticComments", "comments", "comments"), + resourceids.UserSpecifiedSegment("commentId", "commentIdValue"), + } +} + +// String returns a human-readable description of this Comment ID +func (id CommentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + fmt.Sprintf("Issue: %q", id.IssueId), + fmt.Sprintf("Comment: %q", id.CommentId), + } + return fmt.Sprintf("Comment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissuecomment/id_comment_test.go b/resource-manager/apimanagement/2024-05-01/apiissuecomment/id_comment_test.go new file mode 100644 index 00000000000..84b927359ff --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissuecomment/id_comment_test.go @@ -0,0 +1,417 @@ +package apiissuecomment + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &CommentId{} + +func TestNewCommentID(t *testing.T) { + id := NewCommentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue", "commentIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } + + if id.IssueId != "issueIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'IssueId'", id.IssueId, "issueIdValue") + } + + if id.CommentId != "commentIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'CommentId'", id.CommentId, "commentIdValue") + } +} + +func TestFormatCommentID(t *testing.T) { + actual := NewCommentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "issueIdValue", "commentIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue/comments/commentIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCommentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CommentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue/comments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue/comments/commentIdValue", + Expected: &CommentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + IssueId: "issueIdValue", + CommentId: "commentIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue/comments/commentIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCommentID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.IssueId != v.Expected.IssueId { + t.Fatalf("Expected %q but got %q for IssueId", v.Expected.IssueId, actual.IssueId) + } + + if actual.CommentId != v.Expected.CommentId { + t.Fatalf("Expected %q but got %q for CommentId", v.Expected.CommentId, actual.CommentId) + } + + } +} + +func TestParseCommentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CommentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/iSsUeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/iSsUeS/iSsUeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue/comments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/iSsUeS/iSsUeIdVaLuE/cOmMeNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue/comments/commentIdValue", + Expected: &CommentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + IssueId: "issueIdValue", + CommentId: "commentIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/issues/issueIdValue/comments/commentIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/iSsUeS/iSsUeIdVaLuE/cOmMeNtS/cOmMeNtIdVaLuE", + Expected: &CommentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + IssueId: "iSsUeIdVaLuE", + CommentId: "cOmMeNtIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/iSsUeS/iSsUeIdVaLuE/cOmMeNtS/cOmMeNtIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCommentIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.IssueId != v.Expected.IssueId { + t.Fatalf("Expected %q but got %q for IssueId", v.Expected.IssueId, actual.IssueId) + } + + if actual.CommentId != v.Expected.CommentId { + t.Fatalf("Expected %q but got %q for CommentId", v.Expected.CommentId, actual.CommentId) + } + + } +} + +func TestSegmentsForCommentId(t *testing.T) { + segments := CommentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CommentId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissuecomment/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/apiissuecomment/method_createorupdate.go new file mode 100644 index 00000000000..82f8efd70c7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissuecomment/method_createorupdate.go @@ -0,0 +1,88 @@ +package apiissuecomment + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IssueCommentContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c ApiIssueCommentClient) CreateOrUpdate(ctx context.Context, id CommentId, input IssueCommentContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 IssueCommentContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissuecomment/method_delete.go b/resource-manager/apimanagement/2024-05-01/apiissuecomment/method_delete.go new file mode 100644 index 00000000000..725bbb2f2a8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissuecomment/method_delete.go @@ -0,0 +1,76 @@ +package apiissuecomment + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c ApiIssueCommentClient) Delete(ctx context.Context, id CommentId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissuecomment/method_get.go b/resource-manager/apimanagement/2024-05-01/apiissuecomment/method_get.go new file mode 100644 index 00000000000..459dd2af4c6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissuecomment/method_get.go @@ -0,0 +1,54 @@ +package apiissuecomment + +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 *IssueCommentContract +} + +// Get ... +func (c ApiIssueCommentClient) Get(ctx context.Context, id CommentId) (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 IssueCommentContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissuecomment/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/apiissuecomment/method_getentitytag.go new file mode 100644 index 00000000000..a5ce802f723 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissuecomment/method_getentitytag.go @@ -0,0 +1,46 @@ +package apiissuecomment + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c ApiIssueCommentClient) GetEntityTag(ctx context.Context, id CommentId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissuecomment/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/apiissuecomment/method_listbyservice.go new file mode 100644 index 00000000000..a1f56a2f9d7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissuecomment/method_listbyservice.go @@ -0,0 +1,141 @@ +package apiissuecomment + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]IssueCommentContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []IssueCommentContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c ApiIssueCommentClient) ListByService(ctx context.Context, id ApiIssueId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/comments", 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 *[]IssueCommentContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c ApiIssueCommentClient) ListByServiceComplete(ctx context.Context, id ApiIssueId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, IssueCommentContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiIssueCommentClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ApiIssueId, options ListByServiceOperationOptions, predicate IssueCommentContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]IssueCommentContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissuecomment/model_issuecommentcontract.go b/resource-manager/apimanagement/2024-05-01/apiissuecomment/model_issuecommentcontract.go new file mode 100644 index 00000000000..8a58c5bb3f1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissuecomment/model_issuecommentcontract.go @@ -0,0 +1,11 @@ +package apiissuecomment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IssueCommentContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *IssueCommentContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissuecomment/model_issuecommentcontractproperties.go b/resource-manager/apimanagement/2024-05-01/apiissuecomment/model_issuecommentcontractproperties.go new file mode 100644 index 00000000000..4ca4d9f355e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissuecomment/model_issuecommentcontractproperties.go @@ -0,0 +1,28 @@ +package apiissuecomment + +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 IssueCommentContractProperties struct { + CreatedDate *string `json:"createdDate,omitempty"` + Text string `json:"text"` + UserId string `json:"userId"` +} + +func (o *IssueCommentContractProperties) GetCreatedDateAsTime() (*time.Time, error) { + if o.CreatedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *IssueCommentContractProperties) SetCreatedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedDate = &formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/apiissuecomment/predicates.go b/resource-manager/apimanagement/2024-05-01/apiissuecomment/predicates.go new file mode 100644 index 00000000000..1881c0c48df --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissuecomment/predicates.go @@ -0,0 +1,27 @@ +package apiissuecomment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IssueCommentContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p IssueCommentContractOperationPredicate) Matches(input IssueCommentContract) 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/apimanagement/2024-05-01/apiissuecomment/version.go b/resource-manager/apimanagement/2024-05-01/apiissuecomment/version.go new file mode 100644 index 00000000000..198c528a868 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiissuecomment/version.go @@ -0,0 +1,12 @@ +package apiissuecomment + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apiissuecomment/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/README.md b/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/README.md new file mode 100644 index 00000000000..4497d188259 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus` Documentation + +The `apimanagementgatewayskus` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus" +``` + + +### Client Initialization + +```go +client := apimanagementgatewayskus.NewApiManagementGatewaySkusClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiManagementGatewaySkusClient.ListAvailableSkus` + +```go +ctx := context.TODO() +id := apimanagementgatewayskus.NewGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayValue") + +// alternatively `client.ListAvailableSkus(ctx, id)` can be used to do batched pagination +items, err := client.ListAvailableSkusComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/client.go b/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/client.go new file mode 100644 index 00000000000..cdf7fca5094 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/client.go @@ -0,0 +1,26 @@ +package apimanagementgatewayskus + +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 ApiManagementGatewaySkusClient struct { + Client *resourcemanager.Client +} + +func NewApiManagementGatewaySkusClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiManagementGatewaySkusClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apimanagementgatewayskus", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiManagementGatewaySkusClient: %+v", err) + } + + return &ApiManagementGatewaySkusClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/constants.go b/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/constants.go new file mode 100644 index 00000000000..db1b36331a5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/constants.go @@ -0,0 +1,98 @@ +package apimanagementgatewayskus + +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 ApiGatewaySkuType string + +const ( + ApiGatewaySkuTypeStandard ApiGatewaySkuType = "Standard" + ApiGatewaySkuTypeWorkspaceGatewayPremium ApiGatewaySkuType = "WorkspaceGatewayPremium" + ApiGatewaySkuTypeWorkspaceGatewayStandard ApiGatewaySkuType = "WorkspaceGatewayStandard" +) + +func PossibleValuesForApiGatewaySkuType() []string { + return []string{ + string(ApiGatewaySkuTypeStandard), + string(ApiGatewaySkuTypeWorkspaceGatewayPremium), + string(ApiGatewaySkuTypeWorkspaceGatewayStandard), + } +} + +func (s *ApiGatewaySkuType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseApiGatewaySkuType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseApiGatewaySkuType(input string) (*ApiGatewaySkuType, error) { + vals := map[string]ApiGatewaySkuType{ + "standard": ApiGatewaySkuTypeStandard, + "workspacegatewaypremium": ApiGatewaySkuTypeWorkspaceGatewayPremium, + "workspacegatewaystandard": ApiGatewaySkuTypeWorkspaceGatewayStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ApiGatewaySkuType(input) + return &out, nil +} + +type GatewaySkuCapacityScaleType string + +const ( + GatewaySkuCapacityScaleTypeAutomatic GatewaySkuCapacityScaleType = "Automatic" + GatewaySkuCapacityScaleTypeManual GatewaySkuCapacityScaleType = "Manual" + GatewaySkuCapacityScaleTypeNone GatewaySkuCapacityScaleType = "None" +) + +func PossibleValuesForGatewaySkuCapacityScaleType() []string { + return []string{ + string(GatewaySkuCapacityScaleTypeAutomatic), + string(GatewaySkuCapacityScaleTypeManual), + string(GatewaySkuCapacityScaleTypeNone), + } +} + +func (s *GatewaySkuCapacityScaleType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGatewaySkuCapacityScaleType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseGatewaySkuCapacityScaleType(input string) (*GatewaySkuCapacityScaleType, error) { + vals := map[string]GatewaySkuCapacityScaleType{ + "automatic": GatewaySkuCapacityScaleTypeAutomatic, + "manual": GatewaySkuCapacityScaleTypeManual, + "none": GatewaySkuCapacityScaleTypeNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := GatewaySkuCapacityScaleType(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/id_gateway.go b/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/id_gateway.go new file mode 100644 index 00000000000..8b0ae20d1ab --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/id_gateway.go @@ -0,0 +1,130 @@ +package apimanagementgatewayskus + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&GatewayId{}) +} + +var _ resourceids.ResourceId = &GatewayId{} + +// GatewayId is a struct representing the Resource ID for a Gateway +type GatewayId struct { + SubscriptionId string + ResourceGroupName string + GatewayName string +} + +// NewGatewayID returns a new GatewayId struct +func NewGatewayID(subscriptionId string, resourceGroupName string, gatewayName string) GatewayId { + return GatewayId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + GatewayName: gatewayName, + } +} + +// ParseGatewayID parses 'input' into a GatewayId +func ParseGatewayID(input string) (*GatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&GatewayId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGatewayIDInsensitively parses 'input' case-insensitively into a GatewayId +// note: this method should only be used for API response data and not user input +func ParseGatewayIDInsensitively(input string) (*GatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&GatewayId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GatewayId) 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.GatewayName, ok = input.Parsed["gatewayName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "gatewayName", input) + } + + return nil +} + +// ValidateGatewayID checks that 'input' can be parsed as a Gateway ID +func ValidateGatewayID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseGatewayID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Gateway ID +func (id GatewayId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/gateways/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.GatewayName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Gateway ID +func (id GatewayId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticGateways", "gateways", "gateways"), + resourceids.UserSpecifiedSegment("gatewayName", "gatewayValue"), + } +} + +// String returns a human-readable description of this Gateway ID +func (id GatewayId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Gateway Name: %q", id.GatewayName), + } + return fmt.Sprintf("Gateway (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/id_gateway_test.go b/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/id_gateway_test.go new file mode 100644 index 00000000000..c46269ba2fb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/id_gateway_test.go @@ -0,0 +1,282 @@ +package apimanagementgatewayskus + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GatewayId{} + +func TestNewGatewayID(t *testing.T) { + id := NewGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.GatewayName != "gatewayValue" { + t.Fatalf("Expected %q but got %q for Segment 'GatewayName'", id.GatewayName, "gatewayValue") + } +} + +func TestFormatGatewayID(t *testing.T) { + actual := NewGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways/gatewayValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGatewayID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways/gatewayValue", + Expected: &GatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GatewayName: "gatewayValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways/gatewayValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGatewayID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GatewayName != v.Expected.GatewayName { + t.Fatalf("Expected %q but got %q for GatewayName", v.Expected.GatewayName, actual.GatewayName) + } + + } +} + +func TestParseGatewayIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/gAtEwAyS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways/gatewayValue", + Expected: &GatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GatewayName: "gatewayValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/gateways/gatewayValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/gAtEwAyS/gAtEwAyVaLuE", + Expected: &GatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + GatewayName: "gAtEwAyVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/gAtEwAyS/gAtEwAyVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGatewayIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GatewayName != v.Expected.GatewayName { + t.Fatalf("Expected %q but got %q for GatewayName", v.Expected.GatewayName, actual.GatewayName) + } + + } +} + +func TestSegmentsForGatewayId(t *testing.T) { + segments := GatewayId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GatewayId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/method_listavailableskus.go b/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/method_listavailableskus.go new file mode 100644 index 00000000000..6352c01e6b8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/method_listavailableskus.go @@ -0,0 +1,105 @@ +package apimanagementgatewayskus + +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 ListAvailableSkusOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GatewayResourceSkuResult +} + +type ListAvailableSkusCompleteResult struct { + LatestHttpResponse *http.Response + Items []GatewayResourceSkuResult +} + +type ListAvailableSkusCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListAvailableSkusCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListAvailableSkus ... +func (c ApiManagementGatewaySkusClient) ListAvailableSkus(ctx context.Context, id GatewayId) (result ListAvailableSkusOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListAvailableSkusCustomPager{}, + Path: fmt.Sprintf("%s/skus", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]GatewayResourceSkuResult `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListAvailableSkusComplete retrieves all the results into a single object +func (c ApiManagementGatewaySkusClient) ListAvailableSkusComplete(ctx context.Context, id GatewayId) (ListAvailableSkusCompleteResult, error) { + return c.ListAvailableSkusCompleteMatchingPredicate(ctx, id, GatewayResourceSkuResultOperationPredicate{}) +} + +// ListAvailableSkusCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiManagementGatewaySkusClient) ListAvailableSkusCompleteMatchingPredicate(ctx context.Context, id GatewayId, predicate GatewayResourceSkuResultOperationPredicate) (result ListAvailableSkusCompleteResult, err error) { + items := make([]GatewayResourceSkuResult, 0) + + resp, err := c.ListAvailableSkus(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListAvailableSkusCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/model_gatewayresourceskuresult.go b/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/model_gatewayresourceskuresult.go new file mode 100644 index 00000000000..687f34dd4e8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/model_gatewayresourceskuresult.go @@ -0,0 +1,10 @@ +package apimanagementgatewayskus + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewayResourceSkuResult struct { + Capacity *GatewaySkuCapacity `json:"capacity,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + Sku *GatewaySku `json:"sku,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/model_gatewaysku.go b/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/model_gatewaysku.go new file mode 100644 index 00000000000..a140d684f40 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/model_gatewaysku.go @@ -0,0 +1,8 @@ +package apimanagementgatewayskus + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewaySku struct { + Name *ApiGatewaySkuType `json:"name,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/model_gatewayskucapacity.go b/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/model_gatewayskucapacity.go new file mode 100644 index 00000000000..99708eca60f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/model_gatewayskucapacity.go @@ -0,0 +1,11 @@ +package apimanagementgatewayskus + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewaySkuCapacity struct { + Default *int64 `json:"default,omitempty"` + Maximum *int64 `json:"maximum,omitempty"` + Minimum *int64 `json:"minimum,omitempty"` + ScaleType *GatewaySkuCapacityScaleType `json:"scaleType,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/predicates.go b/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/predicates.go new file mode 100644 index 00000000000..231778ff0e3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/predicates.go @@ -0,0 +1,17 @@ +package apimanagementgatewayskus + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewayResourceSkuResultOperationPredicate struct { + ResourceType *string +} + +func (p GatewayResourceSkuResultOperationPredicate) Matches(input GatewayResourceSkuResult) bool { + + if p.ResourceType != nil && (input.ResourceType == nil || *p.ResourceType != *input.ResourceType) { + return false + } + + return true +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/version.go b/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/version.go new file mode 100644 index 00000000000..fe9d40d7b24 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus/version.go @@ -0,0 +1,12 @@ +package apimanagementgatewayskus + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apimanagementgatewayskus/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/README.md b/resource-manager/apimanagement/2024-05-01/apimanagementservice/README.md new file mode 100644 index 00000000000..12aac2b9d10 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/README.md @@ -0,0 +1,238 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apimanagementservice` Documentation + +The `apimanagementservice` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apimanagementservice" +``` + + +### Client Initialization + +```go +client := apimanagementservice.NewApiManagementServiceClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiManagementServiceClient.ApplyNetworkConfigurationUpdates` + +```go +ctx := context.TODO() +id := apimanagementservice.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +payload := apimanagementservice.ApiManagementServiceApplyNetworkConfigurationParameters{ + // ... +} + + +if err := client.ApplyNetworkConfigurationUpdatesThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ApiManagementServiceClient.Backup` + +```go +ctx := context.TODO() +id := apimanagementservice.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +payload := apimanagementservice.ApiManagementServiceBackupRestoreParameters{ + // ... +} + + +if err := client.BackupThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ApiManagementServiceClient.CheckNameAvailability` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +payload := apimanagementservice.ApiManagementServiceCheckNameAvailabilityParameters{ + // ... +} + + +read, err := client.CheckNameAvailability(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiManagementServiceClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := apimanagementservice.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +payload := apimanagementservice.ApiManagementServiceResource{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ApiManagementServiceClient.Delete` + +```go +ctx := context.TODO() +id := apimanagementservice.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ApiManagementServiceClient.Get` + +```go +ctx := context.TODO() +id := apimanagementservice.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +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: `ApiManagementServiceClient.GetDomainOwnershipIdentifier` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +read, err := client.GetDomainOwnershipIdentifier(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiManagementServiceClient.GetSsoToken` + +```go +ctx := context.TODO() +id := apimanagementservice.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +read, err := client.GetSsoToken(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiManagementServiceClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ApiManagementServiceClient.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: `ApiManagementServiceClient.MigrateToStv2` + +```go +ctx := context.TODO() +id := apimanagementservice.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +payload := apimanagementservice.MigrateToStv2Contract{ + // ... +} + + +if err := client.MigrateToStv2ThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ApiManagementServiceClient.Restore` + +```go +ctx := context.TODO() +id := apimanagementservice.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +payload := apimanagementservice.ApiManagementServiceBackupRestoreParameters{ + // ... +} + + +if err := client.RestoreThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ApiManagementServiceClient.Update` + +```go +ctx := context.TODO() +id := apimanagementservice.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +payload := apimanagementservice.ApiManagementServiceUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/client.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/client.go new file mode 100644 index 00000000000..7c5932f7316 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/client.go @@ -0,0 +1,26 @@ +package apimanagementservice + +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 ApiManagementServiceClient struct { + Client *resourcemanager.Client +} + +func NewApiManagementServiceClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiManagementServiceClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apimanagementservice", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiManagementServiceClient: %+v", err) + } + + return &ApiManagementServiceClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/constants.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/constants.go new file mode 100644 index 00000000000..1883e7bcafd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/constants.go @@ -0,0 +1,726 @@ +package apimanagementservice + +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 AccessType string + +const ( + AccessTypeAccessKey AccessType = "AccessKey" + AccessTypeSystemAssignedManagedIdentity AccessType = "SystemAssignedManagedIdentity" + AccessTypeUserAssignedManagedIdentity AccessType = "UserAssignedManagedIdentity" +) + +func PossibleValuesForAccessType() []string { + return []string{ + string(AccessTypeAccessKey), + string(AccessTypeSystemAssignedManagedIdentity), + string(AccessTypeUserAssignedManagedIdentity), + } +} + +func (s *AccessType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAccessType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAccessType(input string) (*AccessType, error) { + vals := map[string]AccessType{ + "accesskey": AccessTypeAccessKey, + "systemassignedmanagedidentity": AccessTypeSystemAssignedManagedIdentity, + "userassignedmanagedidentity": AccessTypeUserAssignedManagedIdentity, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessType(input) + return &out, nil +} + +type CertificateSource string + +const ( + CertificateSourceBuiltIn CertificateSource = "BuiltIn" + CertificateSourceCustom CertificateSource = "Custom" + CertificateSourceKeyVault CertificateSource = "KeyVault" + CertificateSourceManaged CertificateSource = "Managed" +) + +func PossibleValuesForCertificateSource() []string { + return []string{ + string(CertificateSourceBuiltIn), + string(CertificateSourceCustom), + string(CertificateSourceKeyVault), + string(CertificateSourceManaged), + } +} + +func (s *CertificateSource) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCertificateSource(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCertificateSource(input string) (*CertificateSource, error) { + vals := map[string]CertificateSource{ + "builtin": CertificateSourceBuiltIn, + "custom": CertificateSourceCustom, + "keyvault": CertificateSourceKeyVault, + "managed": CertificateSourceManaged, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CertificateSource(input) + return &out, nil +} + +type CertificateStatus string + +const ( + CertificateStatusCompleted CertificateStatus = "Completed" + CertificateStatusFailed CertificateStatus = "Failed" + CertificateStatusInProgress CertificateStatus = "InProgress" +) + +func PossibleValuesForCertificateStatus() []string { + return []string{ + string(CertificateStatusCompleted), + string(CertificateStatusFailed), + string(CertificateStatusInProgress), + } +} + +func (s *CertificateStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCertificateStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCertificateStatus(input string) (*CertificateStatus, error) { + vals := map[string]CertificateStatus{ + "completed": CertificateStatusCompleted, + "failed": CertificateStatusFailed, + "inprogress": CertificateStatusInProgress, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CertificateStatus(input) + return &out, nil +} + +type DeveloperPortalStatus string + +const ( + DeveloperPortalStatusDisabled DeveloperPortalStatus = "Disabled" + DeveloperPortalStatusEnabled DeveloperPortalStatus = "Enabled" +) + +func PossibleValuesForDeveloperPortalStatus() []string { + return []string{ + string(DeveloperPortalStatusDisabled), + string(DeveloperPortalStatusEnabled), + } +} + +func (s *DeveloperPortalStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeveloperPortalStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeveloperPortalStatus(input string) (*DeveloperPortalStatus, error) { + vals := map[string]DeveloperPortalStatus{ + "disabled": DeveloperPortalStatusDisabled, + "enabled": DeveloperPortalStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeveloperPortalStatus(input) + return &out, nil +} + +type HostnameType string + +const ( + HostnameTypeConfigurationApi HostnameType = "ConfigurationApi" + HostnameTypeDeveloperPortal HostnameType = "DeveloperPortal" + HostnameTypeManagement HostnameType = "Management" + HostnameTypePortal HostnameType = "Portal" + HostnameTypeProxy HostnameType = "Proxy" + HostnameTypeScm HostnameType = "Scm" +) + +func PossibleValuesForHostnameType() []string { + return []string{ + string(HostnameTypeConfigurationApi), + string(HostnameTypeDeveloperPortal), + string(HostnameTypeManagement), + string(HostnameTypePortal), + string(HostnameTypeProxy), + string(HostnameTypeScm), + } +} + +func (s *HostnameType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHostnameType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHostnameType(input string) (*HostnameType, error) { + vals := map[string]HostnameType{ + "configurationapi": HostnameTypeConfigurationApi, + "developerportal": HostnameTypeDeveloperPortal, + "management": HostnameTypeManagement, + "portal": HostnameTypePortal, + "proxy": HostnameTypeProxy, + "scm": HostnameTypeScm, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HostnameType(input) + return &out, nil +} + +type LegacyApiState string + +const ( + LegacyApiStateDisabled LegacyApiState = "Disabled" + LegacyApiStateEnabled LegacyApiState = "Enabled" +) + +func PossibleValuesForLegacyApiState() []string { + return []string{ + string(LegacyApiStateDisabled), + string(LegacyApiStateEnabled), + } +} + +func (s *LegacyApiState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLegacyApiState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLegacyApiState(input string) (*LegacyApiState, error) { + vals := map[string]LegacyApiState{ + "disabled": LegacyApiStateDisabled, + "enabled": LegacyApiStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LegacyApiState(input) + return &out, nil +} + +type LegacyPortalStatus string + +const ( + LegacyPortalStatusDisabled LegacyPortalStatus = "Disabled" + LegacyPortalStatusEnabled LegacyPortalStatus = "Enabled" +) + +func PossibleValuesForLegacyPortalStatus() []string { + return []string{ + string(LegacyPortalStatusDisabled), + string(LegacyPortalStatusEnabled), + } +} + +func (s *LegacyPortalStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLegacyPortalStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLegacyPortalStatus(input string) (*LegacyPortalStatus, error) { + vals := map[string]LegacyPortalStatus{ + "disabled": LegacyPortalStatusDisabled, + "enabled": LegacyPortalStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LegacyPortalStatus(input) + return &out, nil +} + +type MigrateToStv2Mode string + +const ( + MigrateToStv2ModeNewIP MigrateToStv2Mode = "NewIP" + MigrateToStv2ModePreserveIP MigrateToStv2Mode = "PreserveIp" +) + +func PossibleValuesForMigrateToStv2Mode() []string { + return []string{ + string(MigrateToStv2ModeNewIP), + string(MigrateToStv2ModePreserveIP), + } +} + +func (s *MigrateToStv2Mode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMigrateToStv2Mode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMigrateToStv2Mode(input string) (*MigrateToStv2Mode, error) { + vals := map[string]MigrateToStv2Mode{ + "newip": MigrateToStv2ModeNewIP, + "preserveip": MigrateToStv2ModePreserveIP, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MigrateToStv2Mode(input) + return &out, nil +} + +type NameAvailabilityReason string + +const ( + NameAvailabilityReasonAlreadyExists NameAvailabilityReason = "AlreadyExists" + NameAvailabilityReasonInvalid NameAvailabilityReason = "Invalid" + NameAvailabilityReasonValid NameAvailabilityReason = "Valid" +) + +func PossibleValuesForNameAvailabilityReason() []string { + return []string{ + string(NameAvailabilityReasonAlreadyExists), + string(NameAvailabilityReasonInvalid), + string(NameAvailabilityReasonValid), + } +} + +func (s *NameAvailabilityReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseNameAvailabilityReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseNameAvailabilityReason(input string) (*NameAvailabilityReason, error) { + vals := map[string]NameAvailabilityReason{ + "alreadyexists": NameAvailabilityReasonAlreadyExists, + "invalid": NameAvailabilityReasonInvalid, + "valid": NameAvailabilityReasonValid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NameAvailabilityReason(input) + return &out, nil +} + +type NatGatewayState string + +const ( + NatGatewayStateDisabled NatGatewayState = "Disabled" + NatGatewayStateEnabled NatGatewayState = "Enabled" +) + +func PossibleValuesForNatGatewayState() []string { + return []string{ + string(NatGatewayStateDisabled), + string(NatGatewayStateEnabled), + } +} + +func (s *NatGatewayState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseNatGatewayState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseNatGatewayState(input string) (*NatGatewayState, error) { + vals := map[string]NatGatewayState{ + "disabled": NatGatewayStateDisabled, + "enabled": NatGatewayStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NatGatewayState(input) + return &out, nil +} + +type PlatformVersion string + +const ( + PlatformVersionMtvOne PlatformVersion = "mtv1" + PlatformVersionStvOne PlatformVersion = "stv1" + PlatformVersionStvTwo PlatformVersion = "stv2" + PlatformVersionStvTwoPointOne PlatformVersion = "stv2.1" + PlatformVersionUndetermined PlatformVersion = "undetermined" +) + +func PossibleValuesForPlatformVersion() []string { + return []string{ + string(PlatformVersionMtvOne), + string(PlatformVersionStvOne), + string(PlatformVersionStvTwo), + string(PlatformVersionStvTwoPointOne), + string(PlatformVersionUndetermined), + } +} + +func (s *PlatformVersion) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePlatformVersion(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePlatformVersion(input string) (*PlatformVersion, error) { + vals := map[string]PlatformVersion{ + "mtv1": PlatformVersionMtvOne, + "stv1": PlatformVersionStvOne, + "stv2": PlatformVersionStvTwo, + "stv2.1": PlatformVersionStvTwoPointOne, + "undetermined": PlatformVersionUndetermined, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PlatformVersion(input) + return &out, nil +} + +type PrivateEndpointServiceConnectionStatus string + +const ( + PrivateEndpointServiceConnectionStatusApproved PrivateEndpointServiceConnectionStatus = "Approved" + PrivateEndpointServiceConnectionStatusPending PrivateEndpointServiceConnectionStatus = "Pending" + PrivateEndpointServiceConnectionStatusRejected PrivateEndpointServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateEndpointServiceConnectionStatus() []string { + return []string{ + string(PrivateEndpointServiceConnectionStatusApproved), + string(PrivateEndpointServiceConnectionStatusPending), + string(PrivateEndpointServiceConnectionStatusRejected), + } +} + +func (s *PrivateEndpointServiceConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointServiceConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointServiceConnectionStatus(input string) (*PrivateEndpointServiceConnectionStatus, error) { + vals := map[string]PrivateEndpointServiceConnectionStatus{ + "approved": PrivateEndpointServiceConnectionStatusApproved, + "pending": PrivateEndpointServiceConnectionStatusPending, + "rejected": PrivateEndpointServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointServiceConnectionStatus(input) + return &out, nil +} + +type PublicNetworkAccess string + +const ( + PublicNetworkAccessDisabled PublicNetworkAccess = "Disabled" + PublicNetworkAccessEnabled PublicNetworkAccess = "Enabled" +) + +func PossibleValuesForPublicNetworkAccess() []string { + return []string{ + string(PublicNetworkAccessDisabled), + string(PublicNetworkAccessEnabled), + } +} + +func (s *PublicNetworkAccess) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePublicNetworkAccess(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePublicNetworkAccess(input string) (*PublicNetworkAccess, error) { + vals := map[string]PublicNetworkAccess{ + "disabled": PublicNetworkAccessDisabled, + "enabled": PublicNetworkAccessEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PublicNetworkAccess(input) + return &out, nil +} + +type SkuType string + +const ( + SkuTypeBasic SkuType = "Basic" + SkuTypeBasicVTwo SkuType = "BasicV2" + SkuTypeConsumption SkuType = "Consumption" + SkuTypeDeveloper SkuType = "Developer" + SkuTypeIsolated SkuType = "Isolated" + SkuTypePremium SkuType = "Premium" + SkuTypeStandard SkuType = "Standard" + SkuTypeStandardVTwo SkuType = "StandardV2" +) + +func PossibleValuesForSkuType() []string { + return []string{ + string(SkuTypeBasic), + string(SkuTypeBasicVTwo), + string(SkuTypeConsumption), + string(SkuTypeDeveloper), + string(SkuTypeIsolated), + string(SkuTypePremium), + string(SkuTypeStandard), + string(SkuTypeStandardVTwo), + } +} + +func (s *SkuType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSkuType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSkuType(input string) (*SkuType, error) { + vals := map[string]SkuType{ + "basic": SkuTypeBasic, + "basicv2": SkuTypeBasicVTwo, + "consumption": SkuTypeConsumption, + "developer": SkuTypeDeveloper, + "isolated": SkuTypeIsolated, + "premium": SkuTypePremium, + "standard": SkuTypeStandard, + "standardv2": SkuTypeStandardVTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SkuType(input) + return &out, nil +} + +type StoreName string + +const ( + StoreNameCertificateAuthority StoreName = "CertificateAuthority" + StoreNameRoot StoreName = "Root" +) + +func PossibleValuesForStoreName() []string { + return []string{ + string(StoreNameCertificateAuthority), + string(StoreNameRoot), + } +} + +func (s *StoreName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStoreName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStoreName(input string) (*StoreName, error) { + vals := map[string]StoreName{ + "certificateauthority": StoreNameCertificateAuthority, + "root": StoreNameRoot, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StoreName(input) + return &out, nil +} + +type VirtualNetworkType string + +const ( + VirtualNetworkTypeExternal VirtualNetworkType = "External" + VirtualNetworkTypeInternal VirtualNetworkType = "Internal" + VirtualNetworkTypeNone VirtualNetworkType = "None" +) + +func PossibleValuesForVirtualNetworkType() []string { + return []string{ + string(VirtualNetworkTypeExternal), + string(VirtualNetworkTypeInternal), + string(VirtualNetworkTypeNone), + } +} + +func (s *VirtualNetworkType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVirtualNetworkType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVirtualNetworkType(input string) (*VirtualNetworkType, error) { + vals := map[string]VirtualNetworkType{ + "external": VirtualNetworkTypeExternal, + "internal": VirtualNetworkTypeInternal, + "none": VirtualNetworkTypeNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VirtualNetworkType(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/id_service.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/id_service.go new file mode 100644 index 00000000000..5183555d0c8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/id_service.go @@ -0,0 +1,130 @@ +package apimanagementservice + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/id_service_test.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/id_service_test.go new file mode 100644 index 00000000000..6b664d7ab78 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/id_service_test.go @@ -0,0 +1,282 @@ +package apimanagementservice + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_applynetworkconfigurationupdates.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_applynetworkconfigurationupdates.go new file mode 100644 index 00000000000..67d5b3e96e1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_applynetworkconfigurationupdates.go @@ -0,0 +1,75 @@ +package apimanagementservice + +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 ApplyNetworkConfigurationUpdatesOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ApiManagementServiceResource +} + +// ApplyNetworkConfigurationUpdates ... +func (c ApiManagementServiceClient) ApplyNetworkConfigurationUpdates(ctx context.Context, id ServiceId, input ApiManagementServiceApplyNetworkConfigurationParameters) (result ApplyNetworkConfigurationUpdatesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/applynetworkconfigurationupdates", 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 +} + +// ApplyNetworkConfigurationUpdatesThenPoll performs ApplyNetworkConfigurationUpdates then polls until it's completed +func (c ApiManagementServiceClient) ApplyNetworkConfigurationUpdatesThenPoll(ctx context.Context, id ServiceId, input ApiManagementServiceApplyNetworkConfigurationParameters) error { + result, err := c.ApplyNetworkConfigurationUpdates(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ApplyNetworkConfigurationUpdates: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ApplyNetworkConfigurationUpdates: %+v", err) + } + + return nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_backup.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_backup.go new file mode 100644 index 00000000000..bc0dc2cfeab --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_backup.go @@ -0,0 +1,75 @@ +package apimanagementservice + +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 BackupOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ApiManagementServiceResource +} + +// Backup ... +func (c ApiManagementServiceClient) Backup(ctx context.Context, id ServiceId, input ApiManagementServiceBackupRestoreParameters) (result BackupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/backup", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// BackupThenPoll performs Backup then polls until it's completed +func (c ApiManagementServiceClient) BackupThenPoll(ctx context.Context, id ServiceId, input ApiManagementServiceBackupRestoreParameters) error { + result, err := c.Backup(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Backup: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Backup: %+v", err) + } + + return nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_checknameavailability.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_checknameavailability.go new file mode 100644 index 00000000000..2a8c875ee1f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_checknameavailability.go @@ -0,0 +1,60 @@ +package apimanagementservice + +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 CheckNameAvailabilityOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ApiManagementServiceNameAvailabilityResult +} + +// CheckNameAvailability ... +func (c ApiManagementServiceClient) CheckNameAvailability(ctx context.Context, id commonids.SubscriptionId, input ApiManagementServiceCheckNameAvailabilityParameters) (result CheckNameAvailabilityOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.ApiManagement/checkNameAvailability", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ApiManagementServiceNameAvailabilityResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_createorupdate.go new file mode 100644 index 00000000000..46810dff420 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_createorupdate.go @@ -0,0 +1,75 @@ +package apimanagementservice + +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 *ApiManagementServiceResource +} + +// CreateOrUpdate ... +func (c ApiManagementServiceClient) CreateOrUpdate(ctx context.Context, id ServiceId, input ApiManagementServiceResource) (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 ApiManagementServiceClient) CreateOrUpdateThenPoll(ctx context.Context, id ServiceId, input ApiManagementServiceResource) 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/apimanagement/2024-05-01/apimanagementservice/method_delete.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_delete.go new file mode 100644 index 00000000000..784be2f9db6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_delete.go @@ -0,0 +1,72 @@ +package apimanagementservice + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ApiManagementServiceResource +} + +// Delete ... +func (c ApiManagementServiceClient) Delete(ctx context.Context, id ServiceId) (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 ApiManagementServiceClient) DeleteThenPoll(ctx context.Context, id ServiceId) 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/apimanagement/2024-05-01/apimanagementservice/method_get.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_get.go new file mode 100644 index 00000000000..771928691f7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_get.go @@ -0,0 +1,54 @@ +package apimanagementservice + +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 *ApiManagementServiceResource +} + +// Get ... +func (c ApiManagementServiceClient) Get(ctx context.Context, id ServiceId) (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 ApiManagementServiceResource + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_getdomainownershipidentifier.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_getdomainownershipidentifier.go new file mode 100644 index 00000000000..40d031a5f83 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_getdomainownershipidentifier.go @@ -0,0 +1,56 @@ +package apimanagementservice + +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 GetDomainOwnershipIdentifierOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ApiManagementServiceGetDomainOwnershipIdentifierResult +} + +// GetDomainOwnershipIdentifier ... +func (c ApiManagementServiceClient) GetDomainOwnershipIdentifier(ctx context.Context, id commonids.SubscriptionId) (result GetDomainOwnershipIdentifierOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.ApiManagement/getDomainOwnershipIdentifier", 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 ApiManagementServiceGetDomainOwnershipIdentifierResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_getssotoken.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_getssotoken.go new file mode 100644 index 00000000000..ecf0a465d0f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_getssotoken.go @@ -0,0 +1,55 @@ +package apimanagementservice + +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 GetSsoTokenOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ApiManagementServiceGetSsoTokenResult +} + +// GetSsoToken ... +func (c ApiManagementServiceClient) GetSsoToken(ctx context.Context, id ServiceId) (result GetSsoTokenOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getssotoken", 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 ApiManagementServiceGetSsoTokenResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_list.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_list.go new file mode 100644 index 00000000000..a543ab50604 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_list.go @@ -0,0 +1,106 @@ +package apimanagementservice + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ApiManagementServiceResource +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ApiManagementServiceResource +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ApiManagementServiceClient) List(ctx context.Context, id commonids.SubscriptionId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.ApiManagement/service", 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 *[]ApiManagementServiceResource `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 ApiManagementServiceClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, ApiManagementServiceResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiManagementServiceClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ApiManagementServiceResourceOperationPredicate) (result ListCompleteResult, err error) { + items := make([]ApiManagementServiceResource, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_listbyresourcegroup.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_listbyresourcegroup.go new file mode 100644 index 00000000000..f7ecb77436b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package apimanagementservice + +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 *[]ApiManagementServiceResource +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []ApiManagementServiceResource +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c ApiManagementServiceClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.ApiManagement/service", 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 *[]ApiManagementServiceResource `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 ApiManagementServiceClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, ApiManagementServiceResourceOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiManagementServiceClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ApiManagementServiceResourceOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]ApiManagementServiceResource, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_migratetostv2.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_migratetostv2.go new file mode 100644 index 00000000000..47361b27a18 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_migratetostv2.go @@ -0,0 +1,75 @@ +package apimanagementservice + +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 MigrateToStv2OperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ApiManagementServiceResource +} + +// MigrateToStv2 ... +func (c ApiManagementServiceClient) MigrateToStv2(ctx context.Context, id ServiceId, input MigrateToStv2Contract) (result MigrateToStv2OperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/migrateToStv2", 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 +} + +// MigrateToStv2ThenPoll performs MigrateToStv2 then polls until it's completed +func (c ApiManagementServiceClient) MigrateToStv2ThenPoll(ctx context.Context, id ServiceId, input MigrateToStv2Contract) error { + result, err := c.MigrateToStv2(ctx, id, input) + if err != nil { + return fmt.Errorf("performing MigrateToStv2: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after MigrateToStv2: %+v", err) + } + + return nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_restore.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_restore.go new file mode 100644 index 00000000000..7df0f46b40b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_restore.go @@ -0,0 +1,75 @@ +package apimanagementservice + +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 RestoreOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ApiManagementServiceResource +} + +// Restore ... +func (c ApiManagementServiceClient) Restore(ctx context.Context, id ServiceId, input ApiManagementServiceBackupRestoreParameters) (result RestoreOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/restore", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// RestoreThenPoll performs Restore then polls until it's completed +func (c ApiManagementServiceClient) RestoreThenPoll(ctx context.Context, id ServiceId, input ApiManagementServiceBackupRestoreParameters) error { + result, err := c.Restore(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Restore: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Restore: %+v", err) + } + + return nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_update.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_update.go new file mode 100644 index 00000000000..30a1b91c59c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/method_update.go @@ -0,0 +1,75 @@ +package apimanagementservice + +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 *ApiManagementServiceResource +} + +// Update ... +func (c ApiManagementServiceClient) Update(ctx context.Context, id ServiceId, input ApiManagementServiceUpdateParameters) (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 ApiManagementServiceClient) UpdateThenPoll(ctx context.Context, id ServiceId, input ApiManagementServiceUpdateParameters) 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/apimanagement/2024-05-01/apimanagementservice/model_additionallocation.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_additionallocation.go new file mode 100644 index 00000000000..3283a7b8de1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_additionallocation.go @@ -0,0 +1,23 @@ +package apimanagementservice + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AdditionalLocation struct { + DisableGateway *bool `json:"disableGateway,omitempty"` + GatewayRegionalUrl *string `json:"gatewayRegionalUrl,omitempty"` + Location string `json:"location"` + NatGatewayState *NatGatewayState `json:"natGatewayState,omitempty"` + OutboundPublicIPAddresses *[]string `json:"outboundPublicIPAddresses,omitempty"` + PlatformVersion *PlatformVersion `json:"platformVersion,omitempty"` + PrivateIPAddresses *[]string `json:"privateIPAddresses,omitempty"` + PublicIPAddressId *string `json:"publicIpAddressId,omitempty"` + PublicIPAddresses *[]string `json:"publicIPAddresses,omitempty"` + Sku ApiManagementServiceSkuProperties `json:"sku"` + VirtualNetworkConfiguration *VirtualNetworkConfiguration `json:"virtualNetworkConfiguration,omitempty"` + Zones *zones.Schema `json:"zones,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementserviceapplynetworkconfigurationparameters.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementserviceapplynetworkconfigurationparameters.go new file mode 100644 index 00000000000..350416344ec --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementserviceapplynetworkconfigurationparameters.go @@ -0,0 +1,8 @@ +package apimanagementservice + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementServiceApplyNetworkConfigurationParameters struct { + Location *string `json:"location,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementservicebackuprestoreparameters.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementservicebackuprestoreparameters.go new file mode 100644 index 00000000000..7c0210d9419 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementservicebackuprestoreparameters.go @@ -0,0 +1,13 @@ +package apimanagementservice + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementServiceBackupRestoreParameters struct { + AccessKey *string `json:"accessKey,omitempty"` + AccessType *AccessType `json:"accessType,omitempty"` + BackupName string `json:"backupName"` + ClientId *string `json:"clientId,omitempty"` + ContainerName string `json:"containerName"` + StorageAccount string `json:"storageAccount"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementservicechecknameavailabilityparameters.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementservicechecknameavailabilityparameters.go new file mode 100644 index 00000000000..f83b6ff078c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementservicechecknameavailabilityparameters.go @@ -0,0 +1,8 @@ +package apimanagementservice + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementServiceCheckNameAvailabilityParameters struct { + Name string `json:"name"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementservicegetdomainownershipidentifierresult.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementservicegetdomainownershipidentifierresult.go new file mode 100644 index 00000000000..1bff72cb739 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementservicegetdomainownershipidentifierresult.go @@ -0,0 +1,8 @@ +package apimanagementservice + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementServiceGetDomainOwnershipIdentifierResult struct { + DomainOwnershipIdentifier *string `json:"domainOwnershipIdentifier,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementservicegetssotokenresult.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementservicegetssotokenresult.go new file mode 100644 index 00000000000..7130e79b7a1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementservicegetssotokenresult.go @@ -0,0 +1,8 @@ +package apimanagementservice + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementServiceGetSsoTokenResult struct { + RedirectUri *string `json:"redirectUri,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementservicenameavailabilityresult.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementservicenameavailabilityresult.go new file mode 100644 index 00000000000..ae214e4d0fc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementservicenameavailabilityresult.go @@ -0,0 +1,10 @@ +package apimanagementservice + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementServiceNameAvailabilityResult struct { + Message *string `json:"message,omitempty"` + NameAvailable *bool `json:"nameAvailable,omitempty"` + Reason *NameAvailabilityReason `json:"reason,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementserviceproperties.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementserviceproperties.go new file mode 100644 index 00000000000..a1901e05e4f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementserviceproperties.go @@ -0,0 +1,58 @@ +package apimanagementservice + +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 ApiManagementServiceProperties struct { + AdditionalLocations *[]AdditionalLocation `json:"additionalLocations,omitempty"` + ApiVersionConstraint *ApiVersionConstraint `json:"apiVersionConstraint,omitempty"` + Certificates *[]CertificateConfiguration `json:"certificates,omitempty"` + ConfigurationApi *ConfigurationApi `json:"configurationApi,omitempty"` + CreatedAtUtc *string `json:"createdAtUtc,omitempty"` + CustomProperties *map[string]string `json:"customProperties,omitempty"` + DeveloperPortalStatus *DeveloperPortalStatus `json:"developerPortalStatus,omitempty"` + DeveloperPortalUrl *string `json:"developerPortalUrl,omitempty"` + DisableGateway *bool `json:"disableGateway,omitempty"` + EnableClientCertificate *bool `json:"enableClientCertificate,omitempty"` + GatewayRegionalUrl *string `json:"gatewayRegionalUrl,omitempty"` + GatewayUrl *string `json:"gatewayUrl,omitempty"` + HostnameConfigurations *[]HostnameConfiguration `json:"hostnameConfigurations,omitempty"` + LegacyPortalStatus *LegacyPortalStatus `json:"legacyPortalStatus,omitempty"` + ManagementApiUrl *string `json:"managementApiUrl,omitempty"` + NatGatewayState *NatGatewayState `json:"natGatewayState,omitempty"` + NotificationSenderEmail *string `json:"notificationSenderEmail,omitempty"` + OutboundPublicIPAddresses *[]string `json:"outboundPublicIPAddresses,omitempty"` + PlatformVersion *PlatformVersion `json:"platformVersion,omitempty"` + PortalUrl *string `json:"portalUrl,omitempty"` + PrivateEndpointConnections *[]RemotePrivateEndpointConnectionWrapper `json:"privateEndpointConnections,omitempty"` + PrivateIPAddresses *[]string `json:"privateIPAddresses,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + PublicIPAddressId *string `json:"publicIpAddressId,omitempty"` + PublicIPAddresses *[]string `json:"publicIPAddresses,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + PublisherEmail string `json:"publisherEmail"` + PublisherName string `json:"publisherName"` + Restore *bool `json:"restore,omitempty"` + ScmUrl *string `json:"scmUrl,omitempty"` + TargetProvisioningState *string `json:"targetProvisioningState,omitempty"` + VirtualNetworkConfiguration *VirtualNetworkConfiguration `json:"virtualNetworkConfiguration,omitempty"` + VirtualNetworkType *VirtualNetworkType `json:"virtualNetworkType,omitempty"` +} + +func (o *ApiManagementServiceProperties) GetCreatedAtUtcAsTime() (*time.Time, error) { + if o.CreatedAtUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedAtUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *ApiManagementServiceProperties) SetCreatedAtUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedAtUtc = &formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementserviceresource.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementserviceresource.go new file mode 100644 index 00000000000..3902958da88 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementserviceresource.go @@ -0,0 +1,24 @@ +package apimanagementservice + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" + "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementServiceResource struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties ApiManagementServiceProperties `json:"properties"` + Sku ApiManagementServiceSkuProperties `json:"sku"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` + Zones *zones.Schema `json:"zones,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementserviceskuproperties.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementserviceskuproperties.go new file mode 100644 index 00000000000..6839fec52ed --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementserviceskuproperties.go @@ -0,0 +1,9 @@ +package apimanagementservice + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementServiceSkuProperties struct { + Capacity int64 `json:"capacity"` + Name SkuType `json:"name"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementserviceupdateparameters.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementserviceupdateparameters.go new file mode 100644 index 00000000000..11a3252fef7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementserviceupdateparameters.go @@ -0,0 +1,21 @@ +package apimanagementservice + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementServiceUpdateParameters struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ApiManagementServiceUpdateProperties `json:"properties,omitempty"` + Sku *ApiManagementServiceSkuProperties `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` + Zones *zones.Schema `json:"zones,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementserviceupdateproperties.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementserviceupdateproperties.go new file mode 100644 index 00000000000..198f9bd1343 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apimanagementserviceupdateproperties.go @@ -0,0 +1,58 @@ +package apimanagementservice + +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 ApiManagementServiceUpdateProperties struct { + AdditionalLocations *[]AdditionalLocation `json:"additionalLocations,omitempty"` + ApiVersionConstraint *ApiVersionConstraint `json:"apiVersionConstraint,omitempty"` + Certificates *[]CertificateConfiguration `json:"certificates,omitempty"` + ConfigurationApi *ConfigurationApi `json:"configurationApi,omitempty"` + CreatedAtUtc *string `json:"createdAtUtc,omitempty"` + CustomProperties *map[string]string `json:"customProperties,omitempty"` + DeveloperPortalStatus *DeveloperPortalStatus `json:"developerPortalStatus,omitempty"` + DeveloperPortalUrl *string `json:"developerPortalUrl,omitempty"` + DisableGateway *bool `json:"disableGateway,omitempty"` + EnableClientCertificate *bool `json:"enableClientCertificate,omitempty"` + GatewayRegionalUrl *string `json:"gatewayRegionalUrl,omitempty"` + GatewayUrl *string `json:"gatewayUrl,omitempty"` + HostnameConfigurations *[]HostnameConfiguration `json:"hostnameConfigurations,omitempty"` + LegacyPortalStatus *LegacyPortalStatus `json:"legacyPortalStatus,omitempty"` + ManagementApiUrl *string `json:"managementApiUrl,omitempty"` + NatGatewayState *NatGatewayState `json:"natGatewayState,omitempty"` + NotificationSenderEmail *string `json:"notificationSenderEmail,omitempty"` + OutboundPublicIPAddresses *[]string `json:"outboundPublicIPAddresses,omitempty"` + PlatformVersion *PlatformVersion `json:"platformVersion,omitempty"` + PortalUrl *string `json:"portalUrl,omitempty"` + PrivateEndpointConnections *[]RemotePrivateEndpointConnectionWrapper `json:"privateEndpointConnections,omitempty"` + PrivateIPAddresses *[]string `json:"privateIPAddresses,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + PublicIPAddressId *string `json:"publicIpAddressId,omitempty"` + PublicIPAddresses *[]string `json:"publicIPAddresses,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + PublisherEmail *string `json:"publisherEmail,omitempty"` + PublisherName *string `json:"publisherName,omitempty"` + Restore *bool `json:"restore,omitempty"` + ScmUrl *string `json:"scmUrl,omitempty"` + TargetProvisioningState *string `json:"targetProvisioningState,omitempty"` + VirtualNetworkConfiguration *VirtualNetworkConfiguration `json:"virtualNetworkConfiguration,omitempty"` + VirtualNetworkType *VirtualNetworkType `json:"virtualNetworkType,omitempty"` +} + +func (o *ApiManagementServiceUpdateProperties) GetCreatedAtUtcAsTime() (*time.Time, error) { + if o.CreatedAtUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedAtUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *ApiManagementServiceUpdateProperties) SetCreatedAtUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedAtUtc = &formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apiversionconstraint.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apiversionconstraint.go new file mode 100644 index 00000000000..449dc717bf0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_apiversionconstraint.go @@ -0,0 +1,8 @@ +package apimanagementservice + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiVersionConstraint struct { + MinApiVersion *string `json:"minApiVersion,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_armidwrapper.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_armidwrapper.go new file mode 100644 index 00000000000..224755cee00 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_armidwrapper.go @@ -0,0 +1,8 @@ +package apimanagementservice + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ArmIdWrapper struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_certificateconfiguration.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_certificateconfiguration.go new file mode 100644 index 00000000000..ce78a7c6e51 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_certificateconfiguration.go @@ -0,0 +1,11 @@ +package apimanagementservice + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CertificateConfiguration struct { + Certificate *CertificateInformation `json:"certificate,omitempty"` + CertificatePassword *string `json:"certificatePassword,omitempty"` + EncodedCertificate *string `json:"encodedCertificate,omitempty"` + StoreName StoreName `json:"storeName"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_certificateinformation.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_certificateinformation.go new file mode 100644 index 00000000000..f9b03432987 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_certificateinformation.go @@ -0,0 +1,25 @@ +package apimanagementservice + +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 CertificateInformation struct { + Expiry string `json:"expiry"` + Subject string `json:"subject"` + Thumbprint string `json:"thumbprint"` +} + +func (o *CertificateInformation) GetExpiryAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.Expiry, "2006-01-02T15:04:05Z07:00") +} + +func (o *CertificateInformation) SetExpiryAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Expiry = formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_configurationapi.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_configurationapi.go new file mode 100644 index 00000000000..1e29f76f560 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_configurationapi.go @@ -0,0 +1,8 @@ +package apimanagementservice + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConfigurationApi struct { + LegacyApi *LegacyApiState `json:"legacyApi,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_hostnameconfiguration.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_hostnameconfiguration.go new file mode 100644 index 00000000000..304fc334363 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_hostnameconfiguration.go @@ -0,0 +1,18 @@ +package apimanagementservice + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HostnameConfiguration struct { + Certificate *CertificateInformation `json:"certificate,omitempty"` + CertificatePassword *string `json:"certificatePassword,omitempty"` + CertificateSource *CertificateSource `json:"certificateSource,omitempty"` + CertificateStatus *CertificateStatus `json:"certificateStatus,omitempty"` + DefaultSslBinding *bool `json:"defaultSslBinding,omitempty"` + EncodedCertificate *string `json:"encodedCertificate,omitempty"` + HostName string `json:"hostName"` + IdentityClientId *string `json:"identityClientId,omitempty"` + KeyVaultId *string `json:"keyVaultId,omitempty"` + NegotiateClientCertificate *bool `json:"negotiateClientCertificate,omitempty"` + Type HostnameType `json:"type"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_migratetostv2contract.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_migratetostv2contract.go new file mode 100644 index 00000000000..7f1e4d52e3f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_migratetostv2contract.go @@ -0,0 +1,8 @@ +package apimanagementservice + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MigrateToStv2Contract struct { + Mode *MigrateToStv2Mode `json:"mode,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_privateendpointconnectionwrapperproperties.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_privateendpointconnectionwrapperproperties.go new file mode 100644 index 00000000000..a8861b48f9f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_privateendpointconnectionwrapperproperties.go @@ -0,0 +1,11 @@ +package apimanagementservice + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionWrapperProperties struct { + GroupIds *[]string `json:"groupIds,omitempty"` + PrivateEndpoint *ArmIdWrapper `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState"` + ProvisioningState *string `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_privatelinkserviceconnectionstate.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..eaf5c7d9c80 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package apimanagementservice + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateEndpointServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_remoteprivateendpointconnectionwrapper.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_remoteprivateendpointconnectionwrapper.go new file mode 100644 index 00000000000..9c2608a5887 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_remoteprivateendpointconnectionwrapper.go @@ -0,0 +1,11 @@ +package apimanagementservice + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RemotePrivateEndpointConnectionWrapper struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionWrapperProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_virtualnetworkconfiguration.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_virtualnetworkconfiguration.go new file mode 100644 index 00000000000..77c716aaab6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/model_virtualnetworkconfiguration.go @@ -0,0 +1,10 @@ +package apimanagementservice + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualNetworkConfiguration struct { + SubnetResourceId *string `json:"subnetResourceId,omitempty"` + Subnetname *string `json:"subnetname,omitempty"` + Vnetid *string `json:"vnetid,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/predicates.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/predicates.go new file mode 100644 index 00000000000..0aedfbdb9df --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/predicates.go @@ -0,0 +1,37 @@ +package apimanagementservice + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementServiceResourceOperationPredicate struct { + Etag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p ApiManagementServiceResourceOperationPredicate) Matches(input ApiManagementServiceResource) bool { + + if p.Etag != nil && (input.Etag == nil || *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementservice/version.go b/resource-manager/apimanagement/2024-05-01/apimanagementservice/version.go new file mode 100644 index 00000000000..bfaf0eacc2b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementservice/version.go @@ -0,0 +1,12 @@ +package apimanagementservice + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apimanagementservice/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/README.md b/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/README.md new file mode 100644 index 00000000000..de89d1e2136 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus` Documentation + +The `apimanagementserviceskus` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus" +``` + + +### Client Initialization + +```go +client := apimanagementserviceskus.NewApiManagementServiceSkusClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiManagementServiceSkusClient.ListAvailableServiceSkus` + +```go +ctx := context.TODO() +id := apimanagementserviceskus.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListAvailableServiceSkus(ctx, id)` can be used to do batched pagination +items, err := client.ListAvailableServiceSkusComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/client.go b/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/client.go new file mode 100644 index 00000000000..33c4554cc31 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/client.go @@ -0,0 +1,26 @@ +package apimanagementserviceskus + +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 ApiManagementServiceSkusClient struct { + Client *resourcemanager.Client +} + +func NewApiManagementServiceSkusClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiManagementServiceSkusClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apimanagementserviceskus", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiManagementServiceSkusClient: %+v", err) + } + + return &ApiManagementServiceSkusClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/constants.go b/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/constants.go new file mode 100644 index 00000000000..51536ca9e37 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/constants.go @@ -0,0 +1,113 @@ +package apimanagementserviceskus + +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 ResourceSkuCapacityScaleType string + +const ( + ResourceSkuCapacityScaleTypeAutomatic ResourceSkuCapacityScaleType = "automatic" + ResourceSkuCapacityScaleTypeManual ResourceSkuCapacityScaleType = "manual" + ResourceSkuCapacityScaleTypeNone ResourceSkuCapacityScaleType = "none" +) + +func PossibleValuesForResourceSkuCapacityScaleType() []string { + return []string{ + string(ResourceSkuCapacityScaleTypeAutomatic), + string(ResourceSkuCapacityScaleTypeManual), + string(ResourceSkuCapacityScaleTypeNone), + } +} + +func (s *ResourceSkuCapacityScaleType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceSkuCapacityScaleType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceSkuCapacityScaleType(input string) (*ResourceSkuCapacityScaleType, error) { + vals := map[string]ResourceSkuCapacityScaleType{ + "automatic": ResourceSkuCapacityScaleTypeAutomatic, + "manual": ResourceSkuCapacityScaleTypeManual, + "none": ResourceSkuCapacityScaleTypeNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceSkuCapacityScaleType(input) + return &out, nil +} + +type SkuType string + +const ( + SkuTypeBasic SkuType = "Basic" + SkuTypeBasicVTwo SkuType = "BasicV2" + SkuTypeConsumption SkuType = "Consumption" + SkuTypeDeveloper SkuType = "Developer" + SkuTypeIsolated SkuType = "Isolated" + SkuTypePremium SkuType = "Premium" + SkuTypeStandard SkuType = "Standard" + SkuTypeStandardVTwo SkuType = "StandardV2" +) + +func PossibleValuesForSkuType() []string { + return []string{ + string(SkuTypeBasic), + string(SkuTypeBasicVTwo), + string(SkuTypeConsumption), + string(SkuTypeDeveloper), + string(SkuTypeIsolated), + string(SkuTypePremium), + string(SkuTypeStandard), + string(SkuTypeStandardVTwo), + } +} + +func (s *SkuType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSkuType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSkuType(input string) (*SkuType, error) { + vals := map[string]SkuType{ + "basic": SkuTypeBasic, + "basicv2": SkuTypeBasicVTwo, + "consumption": SkuTypeConsumption, + "developer": SkuTypeDeveloper, + "isolated": SkuTypeIsolated, + "premium": SkuTypePremium, + "standard": SkuTypeStandard, + "standardv2": SkuTypeStandardVTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SkuType(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/id_service.go b/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/id_service.go new file mode 100644 index 00000000000..1f1fc07284a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/id_service.go @@ -0,0 +1,130 @@ +package apimanagementserviceskus + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/id_service_test.go b/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/id_service_test.go new file mode 100644 index 00000000000..7b8c3368491 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/id_service_test.go @@ -0,0 +1,282 @@ +package apimanagementserviceskus + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/method_listavailableserviceskus.go b/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/method_listavailableserviceskus.go new file mode 100644 index 00000000000..07d00e828ca --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/method_listavailableserviceskus.go @@ -0,0 +1,105 @@ +package apimanagementserviceskus + +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 ListAvailableServiceSkusOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ResourceSkuResult +} + +type ListAvailableServiceSkusCompleteResult struct { + LatestHttpResponse *http.Response + Items []ResourceSkuResult +} + +type ListAvailableServiceSkusCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListAvailableServiceSkusCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListAvailableServiceSkus ... +func (c ApiManagementServiceSkusClient) ListAvailableServiceSkus(ctx context.Context, id ServiceId) (result ListAvailableServiceSkusOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListAvailableServiceSkusCustomPager{}, + Path: fmt.Sprintf("%s/skus", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ResourceSkuResult `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListAvailableServiceSkusComplete retrieves all the results into a single object +func (c ApiManagementServiceSkusClient) ListAvailableServiceSkusComplete(ctx context.Context, id ServiceId) (ListAvailableServiceSkusCompleteResult, error) { + return c.ListAvailableServiceSkusCompleteMatchingPredicate(ctx, id, ResourceSkuResultOperationPredicate{}) +} + +// ListAvailableServiceSkusCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiManagementServiceSkusClient) ListAvailableServiceSkusCompleteMatchingPredicate(ctx context.Context, id ServiceId, predicate ResourceSkuResultOperationPredicate) (result ListAvailableServiceSkusCompleteResult, err error) { + items := make([]ResourceSkuResult, 0) + + resp, err := c.ListAvailableServiceSkus(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListAvailableServiceSkusCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/model_resourcesku.go b/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/model_resourcesku.go new file mode 100644 index 00000000000..4f299e2e718 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/model_resourcesku.go @@ -0,0 +1,8 @@ +package apimanagementserviceskus + +// 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 *SkuType `json:"name,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/model_resourceskucapacity.go b/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/model_resourceskucapacity.go new file mode 100644 index 00000000000..864c2f8079a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/model_resourceskucapacity.go @@ -0,0 +1,11 @@ +package apimanagementserviceskus + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceSkuCapacity struct { + Default *int64 `json:"default,omitempty"` + Maximum *int64 `json:"maximum,omitempty"` + Minimum *int64 `json:"minimum,omitempty"` + ScaleType *ResourceSkuCapacityScaleType `json:"scaleType,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/model_resourceskuresult.go b/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/model_resourceskuresult.go new file mode 100644 index 00000000000..7560f8911e0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/model_resourceskuresult.go @@ -0,0 +1,10 @@ +package apimanagementserviceskus + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceSkuResult struct { + Capacity *ResourceSkuCapacity `json:"capacity,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + Sku *ResourceSku `json:"sku,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/predicates.go b/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/predicates.go new file mode 100644 index 00000000000..7b33648a810 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/predicates.go @@ -0,0 +1,17 @@ +package apimanagementserviceskus + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceSkuResultOperationPredicate struct { + ResourceType *string +} + +func (p ResourceSkuResultOperationPredicate) Matches(input ResourceSkuResult) bool { + + if p.ResourceType != nil && (input.ResourceType == nil || *p.ResourceType != *input.ResourceType) { + return false + } + + return true +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/version.go b/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/version.go new file mode 100644 index 00000000000..91f1b308955 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus/version.go @@ -0,0 +1,12 @@ +package apimanagementserviceskus + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apimanagementserviceskus/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/README.md b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/README.md new file mode 100644 index 00000000000..7f0a0de302a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks` Documentation + +The `apimanagementworkspacelinks` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks" +``` + + +### Client Initialization + +```go +client := apimanagementworkspacelinks.NewApiManagementWorkspaceLinksClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiManagementWorkspaceLinksClient.ApiManagementWorkspaceLinkGet` + +```go +ctx := context.TODO() +id := apimanagementworkspacelinks.NewWorkspaceLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +read, err := client.ApiManagementWorkspaceLinkGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiManagementWorkspaceLinksClient.ListByService` + +```go +ctx := context.TODO() +id := apimanagementworkspacelinks.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id)` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/client.go b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/client.go new file mode 100644 index 00000000000..a29800e3b48 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/client.go @@ -0,0 +1,26 @@ +package apimanagementworkspacelinks + +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 ApiManagementWorkspaceLinksClient struct { + Client *resourcemanager.Client +} + +func NewApiManagementWorkspaceLinksClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiManagementWorkspaceLinksClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apimanagementworkspacelinks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiManagementWorkspaceLinksClient: %+v", err) + } + + return &ApiManagementWorkspaceLinksClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/id_service.go b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/id_service.go new file mode 100644 index 00000000000..df8c971eb74 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/id_service.go @@ -0,0 +1,130 @@ +package apimanagementworkspacelinks + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/id_service_test.go b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/id_service_test.go new file mode 100644 index 00000000000..2f79ea64c62 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/id_service_test.go @@ -0,0 +1,282 @@ +package apimanagementworkspacelinks + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/id_workspacelink.go b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/id_workspacelink.go new file mode 100644 index 00000000000..c69afaa4a01 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/id_workspacelink.go @@ -0,0 +1,139 @@ +package apimanagementworkspacelinks + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceLinkId{}) +} + +var _ resourceids.ResourceId = &WorkspaceLinkId{} + +// WorkspaceLinkId is a struct representing the Resource ID for a Workspace Link +type WorkspaceLinkId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string +} + +// NewWorkspaceLinkID returns a new WorkspaceLinkId struct +func NewWorkspaceLinkID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string) WorkspaceLinkId { + return WorkspaceLinkId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + } +} + +// ParseWorkspaceLinkID parses 'input' into a WorkspaceLinkId +func ParseWorkspaceLinkID(input string) (*WorkspaceLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceLinkId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceLinkIDInsensitively parses 'input' case-insensitively into a WorkspaceLinkId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceLinkIDInsensitively(input string) (*WorkspaceLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceLinkId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceLinkId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + return nil +} + +// ValidateWorkspaceLinkID checks that 'input' can be parsed as a Workspace Link ID +func ValidateWorkspaceLinkID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceLinkID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Link ID +func (id WorkspaceLinkId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaceLinks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Link ID +func (id WorkspaceLinkId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaceLinks", "workspaceLinks", "workspaceLinks"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + } +} + +// String returns a human-readable description of this Workspace Link ID +func (id WorkspaceLinkId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + } + return fmt.Sprintf("Workspace Link (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/id_workspacelink_test.go b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/id_workspacelink_test.go new file mode 100644 index 00000000000..d5f8ba91ee5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/id_workspacelink_test.go @@ -0,0 +1,327 @@ +package apimanagementworkspacelinks + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceLinkId{} + +func TestNewWorkspaceLinkID(t *testing.T) { + id := NewWorkspaceLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } +} + +func TestFormatWorkspaceLinkID(t *testing.T) { + actual := NewWorkspaceLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaceLinks/workspaceIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceLinkID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaceLinks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaceLinks/workspaceIdValue", + Expected: &WorkspaceLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaceLinks/workspaceIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceLinkID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestParseWorkspaceLinkIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaceLinks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeLiNkS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaceLinks/workspaceIdValue", + Expected: &WorkspaceLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaceLinks/workspaceIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeLiNkS/wOrKsPaCeIdVaLuE", + Expected: &WorkspaceLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeLiNkS/wOrKsPaCeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceLinkIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestSegmentsForWorkspaceLinkId(t *testing.T) { + segments := WorkspaceLinkId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceLinkId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/method_apimanagementworkspacelinkget.go b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/method_apimanagementworkspacelinkget.go new file mode 100644 index 00000000000..579aa82e0a9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/method_apimanagementworkspacelinkget.go @@ -0,0 +1,54 @@ +package apimanagementworkspacelinks + +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 ApiManagementWorkspaceLinkGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ApiManagementWorkspaceLinksResource +} + +// ApiManagementWorkspaceLinkGet ... +func (c ApiManagementWorkspaceLinksClient) ApiManagementWorkspaceLinkGet(ctx context.Context, id WorkspaceLinkId) (result ApiManagementWorkspaceLinkGetOperationResponse, 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 ApiManagementWorkspaceLinksResource + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/method_listbyservice.go new file mode 100644 index 00000000000..194ca90fbb6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/method_listbyservice.go @@ -0,0 +1,105 @@ +package apimanagementworkspacelinks + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ApiManagementWorkspaceLinksResource +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ApiManagementWorkspaceLinksResource +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c ApiManagementWorkspaceLinksClient) ListByService(ctx context.Context, id ServiceId) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/workspaceLinks", 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 *[]ApiManagementWorkspaceLinksResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c ApiManagementWorkspaceLinksClient) ListByServiceComplete(ctx context.Context, id ServiceId) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, ApiManagementWorkspaceLinksResourceOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiManagementWorkspaceLinksClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, predicate ApiManagementWorkspaceLinksResourceOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]ApiManagementWorkspaceLinksResource, 0) + + resp, err := c.ListByService(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/model_apimanagementworkspacelinksresource.go b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/model_apimanagementworkspacelinksresource.go new file mode 100644 index 00000000000..cf5e2f97089 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/model_apimanagementworkspacelinksresource.go @@ -0,0 +1,12 @@ +package apimanagementworkspacelinks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementWorkspaceLinksResource struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties WorkspaceLinksBaseProperties `json:"properties"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/model_workspacelinksbaseproperties.go b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/model_workspacelinksbaseproperties.go new file mode 100644 index 00000000000..b08dd7e1ecf --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/model_workspacelinksbaseproperties.go @@ -0,0 +1,9 @@ +package apimanagementworkspacelinks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceLinksBaseProperties struct { + Gateways *[]WorkspaceLinksGateway `json:"gateways,omitempty"` + WorkspaceId *string `json:"workspaceId,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/model_workspacelinksgateway.go b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/model_workspacelinksgateway.go new file mode 100644 index 00000000000..8e879b97aa9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/model_workspacelinksgateway.go @@ -0,0 +1,8 @@ +package apimanagementworkspacelinks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceLinksGateway struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/predicates.go b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/predicates.go new file mode 100644 index 00000000000..333cb270db9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/predicates.go @@ -0,0 +1,32 @@ +package apimanagementworkspacelinks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementWorkspaceLinksResourceOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p ApiManagementWorkspaceLinksResourceOperationPredicate) Matches(input ApiManagementWorkspaceLinksResource) bool { + + if p.Etag != nil && (input.Etag == nil || *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.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/apimanagement/2024-05-01/apimanagementworkspacelinks/version.go b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/version.go new file mode 100644 index 00000000000..477dbd17599 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks/version.go @@ -0,0 +1,12 @@ +package apimanagementworkspacelinks + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apimanagementworkspacelinks/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/README.md b/resource-manager/apimanagement/2024-05-01/apioperation/README.md new file mode 100644 index 00000000000..db356acff23 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/README.md @@ -0,0 +1,234 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apioperation` Documentation + +The `apioperation` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apioperation" +``` + + +### Client Initialization + +```go +client := apioperation.NewApiOperationClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiOperationClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := apioperation.NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "operationIdValue") + +payload := apioperation.OperationContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, apioperation.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiOperationClient.Delete` + +```go +ctx := context.TODO() +id := apioperation.NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "operationIdValue") + +read, err := client.Delete(ctx, id, apioperation.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiOperationClient.Get` + +```go +ctx := context.TODO() +id := apioperation.NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "operationIdValue") + +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: `ApiOperationClient.GetEntityTag` + +```go +ctx := context.TODO() +id := apioperation.NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "operationIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiOperationClient.ListByApi` + +```go +ctx := context.TODO() +id := apioperation.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +// alternatively `client.ListByApi(ctx, id, apioperation.DefaultListByApiOperationOptions())` can be used to do batched pagination +items, err := client.ListByApiComplete(ctx, id, apioperation.DefaultListByApiOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ApiOperationClient.Update` + +```go +ctx := context.TODO() +id := apioperation.NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "operationIdValue") + +payload := apioperation.OperationUpdateContract{ + // ... +} + + +read, err := client.Update(ctx, id, payload, apioperation.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiOperationClient.WorkspaceApiOperationCreateOrUpdate` + +```go +ctx := context.TODO() +id := apioperation.NewApiOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "operationIdValue") + +payload := apioperation.OperationContract{ + // ... +} + + +read, err := client.WorkspaceApiOperationCreateOrUpdate(ctx, id, payload, apioperation.DefaultWorkspaceApiOperationCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiOperationClient.WorkspaceApiOperationDelete` + +```go +ctx := context.TODO() +id := apioperation.NewApiOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "operationIdValue") + +read, err := client.WorkspaceApiOperationDelete(ctx, id, apioperation.DefaultWorkspaceApiOperationDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiOperationClient.WorkspaceApiOperationGet` + +```go +ctx := context.TODO() +id := apioperation.NewApiOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "operationIdValue") + +read, err := client.WorkspaceApiOperationGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiOperationClient.WorkspaceApiOperationGetEntityTag` + +```go +ctx := context.TODO() +id := apioperation.NewApiOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "operationIdValue") + +read, err := client.WorkspaceApiOperationGetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiOperationClient.WorkspaceApiOperationListByApi` + +```go +ctx := context.TODO() +id := apioperation.NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue") + +// alternatively `client.WorkspaceApiOperationListByApi(ctx, id, apioperation.DefaultWorkspaceApiOperationListByApiOperationOptions())` can be used to do batched pagination +items, err := client.WorkspaceApiOperationListByApiComplete(ctx, id, apioperation.DefaultWorkspaceApiOperationListByApiOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ApiOperationClient.WorkspaceApiOperationUpdate` + +```go +ctx := context.TODO() +id := apioperation.NewApiOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "operationIdValue") + +payload := apioperation.OperationUpdateContract{ + // ... +} + + +read, err := client.WorkspaceApiOperationUpdate(ctx, id, payload, apioperation.DefaultWorkspaceApiOperationUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/client.go b/resource-manager/apimanagement/2024-05-01/apioperation/client.go new file mode 100644 index 00000000000..5c9fa6d23e6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/client.go @@ -0,0 +1,26 @@ +package apioperation + +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 ApiOperationClient struct { + Client *resourcemanager.Client +} + +func NewApiOperationClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiOperationClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apioperation", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiOperationClient: %+v", err) + } + + return &ApiOperationClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/id_api.go b/resource-manager/apimanagement/2024-05-01/apioperation/id_api.go new file mode 100644 index 00000000000..253d9153dbc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/id_api.go @@ -0,0 +1,139 @@ +package apioperation + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiId{}) +} + +var _ resourceids.ResourceId = &ApiId{} + +// ApiId is a struct representing the Resource ID for a Api +type ApiId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string +} + +// NewApiID returns a new ApiId struct +func NewApiID(subscriptionId string, resourceGroupName string, serviceName string, apiId string) ApiId { + return ApiId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + } +} + +// ParseApiID parses 'input' into a ApiId +func ParseApiID(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiIDInsensitively parses 'input' case-insensitively into a ApiId +// note: this method should only be used for API response data and not user input +func ParseApiIDInsensitively(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + return nil +} + +// ValidateApiID checks that 'input' can be parsed as a Api ID +func ValidateApiID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api ID +func (id ApiId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api ID +func (id ApiId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + } +} + +// String returns a human-readable description of this Api ID +func (id ApiId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + } + return fmt.Sprintf("Api (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/id_api_test.go b/resource-manager/apimanagement/2024-05-01/apioperation/id_api_test.go new file mode 100644 index 00000000000..50c6fc537a1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/id_api_test.go @@ -0,0 +1,327 @@ +package apioperation + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiId{} + +func TestNewApiID(t *testing.T) { + id := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } +} + +func TestFormatApiID(t *testing.T) { + actual := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestParseApiIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestSegmentsForApiId(t *testing.T) { + segments := ApiId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/id_apioperation.go b/resource-manager/apimanagement/2024-05-01/apioperation/id_apioperation.go new file mode 100644 index 00000000000..57cefcbf920 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/id_apioperation.go @@ -0,0 +1,157 @@ +package apioperation + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiOperationId{}) +} + +var _ resourceids.ResourceId = &ApiOperationId{} + +// ApiOperationId is a struct representing the Resource ID for a Api Operation +type ApiOperationId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + ApiId string + OperationId string +} + +// NewApiOperationID returns a new ApiOperationId struct +func NewApiOperationID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, apiId string, operationId string) ApiOperationId { + return ApiOperationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + ApiId: apiId, + OperationId: operationId, + } +} + +// ParseApiOperationID parses 'input' into a ApiOperationId +func ParseApiOperationID(input string) (*ApiOperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiOperationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiOperationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiOperationIDInsensitively parses 'input' case-insensitively into a ApiOperationId +// note: this method should only be used for API response data and not user input +func ParseApiOperationIDInsensitively(input string) (*ApiOperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiOperationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiOperationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiOperationId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + if id.OperationId, ok = input.Parsed["operationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "operationId", input) + } + + return nil +} + +// ValidateApiOperationID checks that 'input' can be parsed as a Api Operation ID +func ValidateApiOperationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiOperationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api Operation ID +func (id ApiOperationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/apis/%s/operations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.ApiId, id.OperationId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api Operation ID +func (id ApiOperationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + resourceids.StaticSegment("staticOperations", "operations", "operations"), + resourceids.UserSpecifiedSegment("operationId", "operationIdValue"), + } +} + +// String returns a human-readable description of this Api Operation ID +func (id ApiOperationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Api: %q", id.ApiId), + fmt.Sprintf("Operation: %q", id.OperationId), + } + return fmt.Sprintf("Api Operation (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/id_apioperation_test.go b/resource-manager/apimanagement/2024-05-01/apioperation/id_apioperation_test.go new file mode 100644 index 00000000000..0f80bfad625 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/id_apioperation_test.go @@ -0,0 +1,417 @@ +package apioperation + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiOperationId{} + +func TestNewApiOperationID(t *testing.T) { + id := NewApiOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "operationIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } + + if id.OperationId != "operationIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'OperationId'", id.OperationId, "operationIdValue") + } +} + +func TestFormatApiOperationID(t *testing.T) { + actual := NewApiOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "operationIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/operations/operationIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiOperationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiOperationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/operations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/operations/operationIdValue", + Expected: &ApiOperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ApiId: "apiIdValue", + OperationId: "operationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/operations/operationIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiOperationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestParseApiOperationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiOperationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/operations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE/oPeRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/operations/operationIdValue", + Expected: &ApiOperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ApiId: "apiIdValue", + OperationId: "operationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/operations/operationIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE/oPeRaTiOnS/oPeRaTiOnIdVaLuE", + Expected: &ApiOperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + ApiId: "aPiIdVaLuE", + OperationId: "oPeRaTiOnIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE/oPeRaTiOnS/oPeRaTiOnIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiOperationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestSegmentsForApiOperationId(t *testing.T) { + segments := ApiOperationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiOperationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/id_operation.go b/resource-manager/apimanagement/2024-05-01/apioperation/id_operation.go new file mode 100644 index 00000000000..ae47adf61a5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/id_operation.go @@ -0,0 +1,148 @@ +package apioperation + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&OperationId{}) +} + +var _ resourceids.ResourceId = &OperationId{} + +// OperationId is a struct representing the Resource ID for a Operation +type OperationId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string + OperationId string +} + +// NewOperationID returns a new OperationId struct +func NewOperationID(subscriptionId string, resourceGroupName string, serviceName string, apiId string, operationId string) OperationId { + return OperationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + OperationId: operationId, + } +} + +// ParseOperationID parses 'input' into a OperationId +func ParseOperationID(input string) (*OperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&OperationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OperationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseOperationIDInsensitively parses 'input' case-insensitively into a OperationId +// note: this method should only be used for API response data and not user input +func ParseOperationIDInsensitively(input string) (*OperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&OperationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OperationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *OperationId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + if id.OperationId, ok = input.Parsed["operationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "operationId", input) + } + + return nil +} + +// ValidateOperationID checks that 'input' can be parsed as a Operation ID +func ValidateOperationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseOperationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Operation ID +func (id OperationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s/operations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId, id.OperationId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Operation ID +func (id OperationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + resourceids.StaticSegment("staticOperations", "operations", "operations"), + resourceids.UserSpecifiedSegment("operationId", "operationIdValue"), + } +} + +// String returns a human-readable description of this Operation ID +func (id OperationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + fmt.Sprintf("Operation: %q", id.OperationId), + } + return fmt.Sprintf("Operation (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/id_operation_test.go b/resource-manager/apimanagement/2024-05-01/apioperation/id_operation_test.go new file mode 100644 index 00000000000..2175d21b6f5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/id_operation_test.go @@ -0,0 +1,372 @@ +package apioperation + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &OperationId{} + +func TestNewOperationID(t *testing.T) { + id := NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "operationIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } + + if id.OperationId != "operationIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'OperationId'", id.OperationId, "operationIdValue") + } +} + +func TestFormatOperationID(t *testing.T) { + actual := NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "operationIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations/operationIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseOperationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OperationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations/operationIdValue", + Expected: &OperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + OperationId: "operationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations/operationIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOperationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestParseOperationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OperationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/oPeRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations/operationIdValue", + Expected: &OperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + OperationId: "operationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations/operationIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/oPeRaTiOnS/oPeRaTiOnIdVaLuE", + Expected: &OperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + OperationId: "oPeRaTiOnIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/oPeRaTiOnS/oPeRaTiOnIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOperationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestSegmentsForOperationId(t *testing.T) { + segments := OperationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("OperationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/id_workspaceapi.go b/resource-manager/apimanagement/2024-05-01/apioperation/id_workspaceapi.go new file mode 100644 index 00000000000..15a2ebfc5ee --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/id_workspaceapi.go @@ -0,0 +1,148 @@ +package apioperation + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceApiId{}) +} + +var _ resourceids.ResourceId = &WorkspaceApiId{} + +// WorkspaceApiId is a struct representing the Resource ID for a Workspace Api +type WorkspaceApiId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + ApiId string +} + +// NewWorkspaceApiID returns a new WorkspaceApiId struct +func NewWorkspaceApiID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, apiId string) WorkspaceApiId { + return WorkspaceApiId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + ApiId: apiId, + } +} + +// ParseWorkspaceApiID parses 'input' into a WorkspaceApiId +func ParseWorkspaceApiID(input string) (*WorkspaceApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceApiId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceApiIDInsensitively parses 'input' case-insensitively into a WorkspaceApiId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceApiIDInsensitively(input string) (*WorkspaceApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceApiId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceApiId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + return nil +} + +// ValidateWorkspaceApiID checks that 'input' can be parsed as a Workspace Api ID +func ValidateWorkspaceApiID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceApiID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Api ID +func (id WorkspaceApiId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/apis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.ApiId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Api ID +func (id WorkspaceApiId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + } +} + +// String returns a human-readable description of this Workspace Api ID +func (id WorkspaceApiId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Api: %q", id.ApiId), + } + return fmt.Sprintf("Workspace Api (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/id_workspaceapi_test.go b/resource-manager/apimanagement/2024-05-01/apioperation/id_workspaceapi_test.go new file mode 100644 index 00000000000..1dc42f24636 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/id_workspaceapi_test.go @@ -0,0 +1,372 @@ +package apioperation + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceApiId{} + +func TestNewWorkspaceApiID(t *testing.T) { + id := NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } +} + +func TestFormatWorkspaceApiID(t *testing.T) { + actual := NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceApiID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue", + Expected: &WorkspaceApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceApiID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestParseWorkspaceApiIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue", + Expected: &WorkspaceApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE", + Expected: &WorkspaceApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + ApiId: "aPiIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceApiIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestSegmentsForWorkspaceApiId(t *testing.T) { + segments := WorkspaceApiId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceApiId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/apioperation/method_createorupdate.go new file mode 100644 index 00000000000..ee86a38b0bc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/method_createorupdate.go @@ -0,0 +1,88 @@ +package apioperation + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *OperationContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c ApiOperationClient) CreateOrUpdate(ctx context.Context, id OperationId, input OperationContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 OperationContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/method_delete.go b/resource-manager/apimanagement/2024-05-01/apioperation/method_delete.go new file mode 100644 index 00000000000..ee390d245b3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/method_delete.go @@ -0,0 +1,76 @@ +package apioperation + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c ApiOperationClient) Delete(ctx context.Context, id OperationId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/method_get.go b/resource-manager/apimanagement/2024-05-01/apioperation/method_get.go new file mode 100644 index 00000000000..7fed3585ab9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/method_get.go @@ -0,0 +1,54 @@ +package apioperation + +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 *OperationContract +} + +// Get ... +func (c ApiOperationClient) Get(ctx context.Context, id OperationId) (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 OperationContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/apioperation/method_getentitytag.go new file mode 100644 index 00000000000..520a7b92e36 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/method_getentitytag.go @@ -0,0 +1,46 @@ +package apioperation + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c ApiOperationClient) GetEntityTag(ctx context.Context, id OperationId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/method_listbyapi.go b/resource-manager/apimanagement/2024-05-01/apioperation/method_listbyapi.go new file mode 100644 index 00000000000..df8d3b45502 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/method_listbyapi.go @@ -0,0 +1,145 @@ +package apioperation + +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 ListByApiOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]OperationContract +} + +type ListByApiCompleteResult struct { + LatestHttpResponse *http.Response + Items []OperationContract +} + +type ListByApiOperationOptions struct { + Filter *string + Skip *int64 + Tags *string + Top *int64 +} + +func DefaultListByApiOperationOptions() ListByApiOperationOptions { + return ListByApiOperationOptions{} +} + +func (o ListByApiOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByApiOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByApiOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Tags != nil { + out.Append("tags", fmt.Sprintf("%v", *o.Tags)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByApiCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByApiCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByApi ... +func (c ApiOperationClient) ListByApi(ctx context.Context, id ApiId, options ListByApiOperationOptions) (result ListByApiOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByApiCustomPager{}, + Path: fmt.Sprintf("%s/operations", 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 *[]OperationContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByApiComplete retrieves all the results into a single object +func (c ApiOperationClient) ListByApiComplete(ctx context.Context, id ApiId, options ListByApiOperationOptions) (ListByApiCompleteResult, error) { + return c.ListByApiCompleteMatchingPredicate(ctx, id, options, OperationContractOperationPredicate{}) +} + +// ListByApiCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiOperationClient) ListByApiCompleteMatchingPredicate(ctx context.Context, id ApiId, options ListByApiOperationOptions, predicate OperationContractOperationPredicate) (result ListByApiCompleteResult, err error) { + items := make([]OperationContract, 0) + + resp, err := c.ListByApi(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByApiCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/method_update.go b/resource-manager/apimanagement/2024-05-01/apioperation/method_update.go new file mode 100644 index 00000000000..005fc98f21a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/method_update.go @@ -0,0 +1,87 @@ +package apioperation + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *OperationContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c ApiOperationClient) Update(ctx context.Context, id OperationId, input OperationUpdateContract, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 OperationContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/method_workspaceapioperationcreateorupdate.go b/resource-manager/apimanagement/2024-05-01/apioperation/method_workspaceapioperationcreateorupdate.go new file mode 100644 index 00000000000..31e0a6ea5fe --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/method_workspaceapioperationcreateorupdate.go @@ -0,0 +1,88 @@ +package apioperation + +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 WorkspaceApiOperationCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *OperationContract +} + +type WorkspaceApiOperationCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceApiOperationCreateOrUpdateOperationOptions() WorkspaceApiOperationCreateOrUpdateOperationOptions { + return WorkspaceApiOperationCreateOrUpdateOperationOptions{} +} + +func (o WorkspaceApiOperationCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceApiOperationCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiOperationCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceApiOperationCreateOrUpdate ... +func (c ApiOperationClient) WorkspaceApiOperationCreateOrUpdate(ctx context.Context, id ApiOperationId, input OperationContract, options WorkspaceApiOperationCreateOrUpdateOperationOptions) (result WorkspaceApiOperationCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 OperationContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/method_workspaceapioperationdelete.go b/resource-manager/apimanagement/2024-05-01/apioperation/method_workspaceapioperationdelete.go new file mode 100644 index 00000000000..803c543da5b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/method_workspaceapioperationdelete.go @@ -0,0 +1,76 @@ +package apioperation + +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 WorkspaceApiOperationDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type WorkspaceApiOperationDeleteOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceApiOperationDeleteOperationOptions() WorkspaceApiOperationDeleteOperationOptions { + return WorkspaceApiOperationDeleteOperationOptions{} +} + +func (o WorkspaceApiOperationDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceApiOperationDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiOperationDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceApiOperationDelete ... +func (c ApiOperationClient) WorkspaceApiOperationDelete(ctx context.Context, id ApiOperationId, options WorkspaceApiOperationDeleteOperationOptions) (result WorkspaceApiOperationDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/method_workspaceapioperationget.go b/resource-manager/apimanagement/2024-05-01/apioperation/method_workspaceapioperationget.go new file mode 100644 index 00000000000..2da88a66a2f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/method_workspaceapioperationget.go @@ -0,0 +1,54 @@ +package apioperation + +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 WorkspaceApiOperationGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *OperationContract +} + +// WorkspaceApiOperationGet ... +func (c ApiOperationClient) WorkspaceApiOperationGet(ctx context.Context, id ApiOperationId) (result WorkspaceApiOperationGetOperationResponse, 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 OperationContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/method_workspaceapioperationgetentitytag.go b/resource-manager/apimanagement/2024-05-01/apioperation/method_workspaceapioperationgetentitytag.go new file mode 100644 index 00000000000..c9cec8363f9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/method_workspaceapioperationgetentitytag.go @@ -0,0 +1,46 @@ +package apioperation + +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 WorkspaceApiOperationGetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceApiOperationGetEntityTag ... +func (c ApiOperationClient) WorkspaceApiOperationGetEntityTag(ctx context.Context, id ApiOperationId) (result WorkspaceApiOperationGetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/method_workspaceapioperationlistbyapi.go b/resource-manager/apimanagement/2024-05-01/apioperation/method_workspaceapioperationlistbyapi.go new file mode 100644 index 00000000000..dfa7091cdf8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/method_workspaceapioperationlistbyapi.go @@ -0,0 +1,145 @@ +package apioperation + +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 WorkspaceApiOperationListByApiOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]OperationContract +} + +type WorkspaceApiOperationListByApiCompleteResult struct { + LatestHttpResponse *http.Response + Items []OperationContract +} + +type WorkspaceApiOperationListByApiOperationOptions struct { + Filter *string + Skip *int64 + Tags *string + Top *int64 +} + +func DefaultWorkspaceApiOperationListByApiOperationOptions() WorkspaceApiOperationListByApiOperationOptions { + return WorkspaceApiOperationListByApiOperationOptions{} +} + +func (o WorkspaceApiOperationListByApiOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceApiOperationListByApiOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiOperationListByApiOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Tags != nil { + out.Append("tags", fmt.Sprintf("%v", *o.Tags)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspaceApiOperationListByApiCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceApiOperationListByApiCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceApiOperationListByApi ... +func (c ApiOperationClient) WorkspaceApiOperationListByApi(ctx context.Context, id WorkspaceApiId, options WorkspaceApiOperationListByApiOperationOptions) (result WorkspaceApiOperationListByApiOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspaceApiOperationListByApiCustomPager{}, + Path: fmt.Sprintf("%s/operations", 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 *[]OperationContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceApiOperationListByApiComplete retrieves all the results into a single object +func (c ApiOperationClient) WorkspaceApiOperationListByApiComplete(ctx context.Context, id WorkspaceApiId, options WorkspaceApiOperationListByApiOperationOptions) (WorkspaceApiOperationListByApiCompleteResult, error) { + return c.WorkspaceApiOperationListByApiCompleteMatchingPredicate(ctx, id, options, OperationContractOperationPredicate{}) +} + +// WorkspaceApiOperationListByApiCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiOperationClient) WorkspaceApiOperationListByApiCompleteMatchingPredicate(ctx context.Context, id WorkspaceApiId, options WorkspaceApiOperationListByApiOperationOptions, predicate OperationContractOperationPredicate) (result WorkspaceApiOperationListByApiCompleteResult, err error) { + items := make([]OperationContract, 0) + + resp, err := c.WorkspaceApiOperationListByApi(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceApiOperationListByApiCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/method_workspaceapioperationupdate.go b/resource-manager/apimanagement/2024-05-01/apioperation/method_workspaceapioperationupdate.go new file mode 100644 index 00000000000..b485b35b34a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/method_workspaceapioperationupdate.go @@ -0,0 +1,87 @@ +package apioperation + +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 WorkspaceApiOperationUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *OperationContract +} + +type WorkspaceApiOperationUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceApiOperationUpdateOperationOptions() WorkspaceApiOperationUpdateOperationOptions { + return WorkspaceApiOperationUpdateOperationOptions{} +} + +func (o WorkspaceApiOperationUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceApiOperationUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiOperationUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceApiOperationUpdate ... +func (c ApiOperationClient) WorkspaceApiOperationUpdate(ctx context.Context, id ApiOperationId, input OperationUpdateContract, options WorkspaceApiOperationUpdateOperationOptions) (result WorkspaceApiOperationUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 OperationContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/model_operationcontract.go b/resource-manager/apimanagement/2024-05-01/apioperation/model_operationcontract.go new file mode 100644 index 00000000000..873a3fddabc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/model_operationcontract.go @@ -0,0 +1,11 @@ +package apioperation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *OperationContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/model_operationcontractproperties.go b/resource-manager/apimanagement/2024-05-01/apioperation/model_operationcontractproperties.go new file mode 100644 index 00000000000..646f7cc73ae --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/model_operationcontractproperties.go @@ -0,0 +1,15 @@ +package apioperation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationContractProperties struct { + Description *string `json:"description,omitempty"` + DisplayName string `json:"displayName"` + Method string `json:"method"` + Policies *string `json:"policies,omitempty"` + Request *RequestContract `json:"request,omitempty"` + Responses *[]ResponseContract `json:"responses,omitempty"` + TemplateParameters *[]ParameterContract `json:"templateParameters,omitempty"` + UrlTemplate string `json:"urlTemplate"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/model_operationupdatecontract.go b/resource-manager/apimanagement/2024-05-01/apioperation/model_operationupdatecontract.go new file mode 100644 index 00000000000..74d6e9a0d9a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/model_operationupdatecontract.go @@ -0,0 +1,8 @@ +package apioperation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationUpdateContract struct { + Properties *OperationUpdateContractProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/model_operationupdatecontractproperties.go b/resource-manager/apimanagement/2024-05-01/apioperation/model_operationupdatecontractproperties.go new file mode 100644 index 00000000000..a0d2d1d4420 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/model_operationupdatecontractproperties.go @@ -0,0 +1,15 @@ +package apioperation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationUpdateContractProperties struct { + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + Method *string `json:"method,omitempty"` + Policies *string `json:"policies,omitempty"` + Request *RequestContract `json:"request,omitempty"` + Responses *[]ResponseContract `json:"responses,omitempty"` + TemplateParameters *[]ParameterContract `json:"templateParameters,omitempty"` + UrlTemplate *string `json:"urlTemplate,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/model_parametercontract.go b/resource-manager/apimanagement/2024-05-01/apioperation/model_parametercontract.go new file mode 100644 index 00000000000..93f3674edad --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/model_parametercontract.go @@ -0,0 +1,16 @@ +package apioperation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ParameterContract struct { + DefaultValue *string `json:"defaultValue,omitempty"` + Description *string `json:"description,omitempty"` + Examples *map[string]ParameterExampleContract `json:"examples,omitempty"` + Name string `json:"name"` + Required *bool `json:"required,omitempty"` + SchemaId *string `json:"schemaId,omitempty"` + Type string `json:"type"` + TypeName *string `json:"typeName,omitempty"` + Values *[]string `json:"values,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/model_parameterexamplecontract.go b/resource-manager/apimanagement/2024-05-01/apioperation/model_parameterexamplecontract.go new file mode 100644 index 00000000000..2dd4619cc06 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/model_parameterexamplecontract.go @@ -0,0 +1,11 @@ +package apioperation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ParameterExampleContract struct { + Description *string `json:"description,omitempty"` + ExternalValue *string `json:"externalValue,omitempty"` + Summary *string `json:"summary,omitempty"` + Value *interface{} `json:"value,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/model_representationcontract.go b/resource-manager/apimanagement/2024-05-01/apioperation/model_representationcontract.go new file mode 100644 index 00000000000..b4b66797887 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/model_representationcontract.go @@ -0,0 +1,12 @@ +package apioperation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RepresentationContract struct { + ContentType string `json:"contentType"` + Examples *map[string]ParameterExampleContract `json:"examples,omitempty"` + FormParameters *[]ParameterContract `json:"formParameters,omitempty"` + SchemaId *string `json:"schemaId,omitempty"` + TypeName *string `json:"typeName,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/model_requestcontract.go b/resource-manager/apimanagement/2024-05-01/apioperation/model_requestcontract.go new file mode 100644 index 00000000000..3fac1e8f62b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/model_requestcontract.go @@ -0,0 +1,11 @@ +package apioperation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RequestContract struct { + Description *string `json:"description,omitempty"` + Headers *[]ParameterContract `json:"headers,omitempty"` + QueryParameters *[]ParameterContract `json:"queryParameters,omitempty"` + Representations *[]RepresentationContract `json:"representations,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/model_responsecontract.go b/resource-manager/apimanagement/2024-05-01/apioperation/model_responsecontract.go new file mode 100644 index 00000000000..34e9fe29b99 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/model_responsecontract.go @@ -0,0 +1,11 @@ +package apioperation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResponseContract struct { + Description *string `json:"description,omitempty"` + Headers *[]ParameterContract `json:"headers,omitempty"` + Representations *[]RepresentationContract `json:"representations,omitempty"` + StatusCode int64 `json:"statusCode"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperation/predicates.go b/resource-manager/apimanagement/2024-05-01/apioperation/predicates.go new file mode 100644 index 00000000000..80cc934a835 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/predicates.go @@ -0,0 +1,27 @@ +package apioperation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p OperationContractOperationPredicate) Matches(input OperationContract) 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/apimanagement/2024-05-01/apioperation/version.go b/resource-manager/apimanagement/2024-05-01/apioperation/version.go new file mode 100644 index 00000000000..990a5c1717d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperation/version.go @@ -0,0 +1,12 @@ +package apioperation + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apioperation/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationpolicy/README.md b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/README.md new file mode 100644 index 00000000000..2dee1c23a83 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/README.md @@ -0,0 +1,192 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apioperationpolicy` Documentation + +The `apioperationpolicy` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apioperationpolicy" +``` + + +### Client Initialization + +```go +client := apioperationpolicy.NewApiOperationPolicyClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiOperationPolicyClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := apioperationpolicy.NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "operationIdValue") + +payload := apioperationpolicy.PolicyContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, apioperationpolicy.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiOperationPolicyClient.Delete` + +```go +ctx := context.TODO() +id := apioperationpolicy.NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "operationIdValue") + +read, err := client.Delete(ctx, id, apioperationpolicy.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiOperationPolicyClient.Get` + +```go +ctx := context.TODO() +id := apioperationpolicy.NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "operationIdValue") + +read, err := client.Get(ctx, id, apioperationpolicy.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiOperationPolicyClient.GetEntityTag` + +```go +ctx := context.TODO() +id := apioperationpolicy.NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "operationIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiOperationPolicyClient.ListByOperation` + +```go +ctx := context.TODO() +id := apioperationpolicy.NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "operationIdValue") + +// alternatively `client.ListByOperation(ctx, id)` can be used to do batched pagination +items, err := client.ListByOperationComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ApiOperationPolicyClient.WorkspaceApiOperationPolicyCreateOrUpdate` + +```go +ctx := context.TODO() +id := apioperationpolicy.NewApiOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "operationIdValue") + +payload := apioperationpolicy.PolicyContract{ + // ... +} + + +read, err := client.WorkspaceApiOperationPolicyCreateOrUpdate(ctx, id, payload, apioperationpolicy.DefaultWorkspaceApiOperationPolicyCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiOperationPolicyClient.WorkspaceApiOperationPolicyDelete` + +```go +ctx := context.TODO() +id := apioperationpolicy.NewApiOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "operationIdValue") + +read, err := client.WorkspaceApiOperationPolicyDelete(ctx, id, apioperationpolicy.DefaultWorkspaceApiOperationPolicyDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiOperationPolicyClient.WorkspaceApiOperationPolicyGet` + +```go +ctx := context.TODO() +id := apioperationpolicy.NewApiOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "operationIdValue") + +read, err := client.WorkspaceApiOperationPolicyGet(ctx, id, apioperationpolicy.DefaultWorkspaceApiOperationPolicyGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiOperationPolicyClient.WorkspaceApiOperationPolicyGetEntityTag` + +```go +ctx := context.TODO() +id := apioperationpolicy.NewApiOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "operationIdValue") + +read, err := client.WorkspaceApiOperationPolicyGetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiOperationPolicyClient.WorkspaceApiOperationPolicyListByOperation` + +```go +ctx := context.TODO() +id := apioperationpolicy.NewApiOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "operationIdValue") + +// alternatively `client.WorkspaceApiOperationPolicyListByOperation(ctx, id)` can be used to do batched pagination +items, err := client.WorkspaceApiOperationPolicyListByOperationComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/apioperationpolicy/client.go b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/client.go new file mode 100644 index 00000000000..4c1ef477115 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/client.go @@ -0,0 +1,26 @@ +package apioperationpolicy + +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 ApiOperationPolicyClient struct { + Client *resourcemanager.Client +} + +func NewApiOperationPolicyClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiOperationPolicyClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apioperationpolicy", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiOperationPolicyClient: %+v", err) + } + + return &ApiOperationPolicyClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationpolicy/constants.go b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/constants.go new file mode 100644 index 00000000000..5a4b902d0cf --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/constants.go @@ -0,0 +1,98 @@ +package apioperationpolicy + +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 PolicyContentFormat string + +const ( + PolicyContentFormatRawxml PolicyContentFormat = "rawxml" + PolicyContentFormatRawxmlNegativelink PolicyContentFormat = "rawxml-link" + PolicyContentFormatXml PolicyContentFormat = "xml" + PolicyContentFormatXmlNegativelink PolicyContentFormat = "xml-link" +) + +func PossibleValuesForPolicyContentFormat() []string { + return []string{ + string(PolicyContentFormatRawxml), + string(PolicyContentFormatRawxmlNegativelink), + string(PolicyContentFormatXml), + string(PolicyContentFormatXmlNegativelink), + } +} + +func (s *PolicyContentFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePolicyContentFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePolicyContentFormat(input string) (*PolicyContentFormat, error) { + vals := map[string]PolicyContentFormat{ + "rawxml": PolicyContentFormatRawxml, + "rawxml-link": PolicyContentFormatRawxmlNegativelink, + "xml": PolicyContentFormatXml, + "xml-link": PolicyContentFormatXmlNegativelink, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyContentFormat(input) + return &out, nil +} + +type PolicyExportFormat string + +const ( + PolicyExportFormatRawxml PolicyExportFormat = "rawxml" + PolicyExportFormatXml PolicyExportFormat = "xml" +) + +func PossibleValuesForPolicyExportFormat() []string { + return []string{ + string(PolicyExportFormatRawxml), + string(PolicyExportFormatXml), + } +} + +func (s *PolicyExportFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePolicyExportFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePolicyExportFormat(input string) (*PolicyExportFormat, error) { + vals := map[string]PolicyExportFormat{ + "rawxml": PolicyExportFormatRawxml, + "xml": PolicyExportFormatXml, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyExportFormat(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationpolicy/id_apioperation.go b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/id_apioperation.go new file mode 100644 index 00000000000..15b5b760791 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/id_apioperation.go @@ -0,0 +1,157 @@ +package apioperationpolicy + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiOperationId{}) +} + +var _ resourceids.ResourceId = &ApiOperationId{} + +// ApiOperationId is a struct representing the Resource ID for a Api Operation +type ApiOperationId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + ApiId string + OperationId string +} + +// NewApiOperationID returns a new ApiOperationId struct +func NewApiOperationID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, apiId string, operationId string) ApiOperationId { + return ApiOperationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + ApiId: apiId, + OperationId: operationId, + } +} + +// ParseApiOperationID parses 'input' into a ApiOperationId +func ParseApiOperationID(input string) (*ApiOperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiOperationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiOperationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiOperationIDInsensitively parses 'input' case-insensitively into a ApiOperationId +// note: this method should only be used for API response data and not user input +func ParseApiOperationIDInsensitively(input string) (*ApiOperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiOperationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiOperationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiOperationId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + if id.OperationId, ok = input.Parsed["operationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "operationId", input) + } + + return nil +} + +// ValidateApiOperationID checks that 'input' can be parsed as a Api Operation ID +func ValidateApiOperationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiOperationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api Operation ID +func (id ApiOperationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/apis/%s/operations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.ApiId, id.OperationId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api Operation ID +func (id ApiOperationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + resourceids.StaticSegment("staticOperations", "operations", "operations"), + resourceids.UserSpecifiedSegment("operationId", "operationIdValue"), + } +} + +// String returns a human-readable description of this Api Operation ID +func (id ApiOperationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Api: %q", id.ApiId), + fmt.Sprintf("Operation: %q", id.OperationId), + } + return fmt.Sprintf("Api Operation (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationpolicy/id_apioperation_test.go b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/id_apioperation_test.go new file mode 100644 index 00000000000..7f32a2c553f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/id_apioperation_test.go @@ -0,0 +1,417 @@ +package apioperationpolicy + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiOperationId{} + +func TestNewApiOperationID(t *testing.T) { + id := NewApiOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "operationIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } + + if id.OperationId != "operationIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'OperationId'", id.OperationId, "operationIdValue") + } +} + +func TestFormatApiOperationID(t *testing.T) { + actual := NewApiOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "operationIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/operations/operationIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiOperationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiOperationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/operations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/operations/operationIdValue", + Expected: &ApiOperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ApiId: "apiIdValue", + OperationId: "operationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/operations/operationIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiOperationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestParseApiOperationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiOperationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/operations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE/oPeRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/operations/operationIdValue", + Expected: &ApiOperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ApiId: "apiIdValue", + OperationId: "operationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/operations/operationIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE/oPeRaTiOnS/oPeRaTiOnIdVaLuE", + Expected: &ApiOperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + ApiId: "aPiIdVaLuE", + OperationId: "oPeRaTiOnIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE/oPeRaTiOnS/oPeRaTiOnIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiOperationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestSegmentsForApiOperationId(t *testing.T) { + segments := ApiOperationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiOperationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationpolicy/id_operation.go b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/id_operation.go new file mode 100644 index 00000000000..a9f5f2e9bd1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/id_operation.go @@ -0,0 +1,148 @@ +package apioperationpolicy + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&OperationId{}) +} + +var _ resourceids.ResourceId = &OperationId{} + +// OperationId is a struct representing the Resource ID for a Operation +type OperationId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string + OperationId string +} + +// NewOperationID returns a new OperationId struct +func NewOperationID(subscriptionId string, resourceGroupName string, serviceName string, apiId string, operationId string) OperationId { + return OperationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + OperationId: operationId, + } +} + +// ParseOperationID parses 'input' into a OperationId +func ParseOperationID(input string) (*OperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&OperationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OperationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseOperationIDInsensitively parses 'input' case-insensitively into a OperationId +// note: this method should only be used for API response data and not user input +func ParseOperationIDInsensitively(input string) (*OperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&OperationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OperationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *OperationId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + if id.OperationId, ok = input.Parsed["operationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "operationId", input) + } + + return nil +} + +// ValidateOperationID checks that 'input' can be parsed as a Operation ID +func ValidateOperationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseOperationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Operation ID +func (id OperationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s/operations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId, id.OperationId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Operation ID +func (id OperationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + resourceids.StaticSegment("staticOperations", "operations", "operations"), + resourceids.UserSpecifiedSegment("operationId", "operationIdValue"), + } +} + +// String returns a human-readable description of this Operation ID +func (id OperationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + fmt.Sprintf("Operation: %q", id.OperationId), + } + return fmt.Sprintf("Operation (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationpolicy/id_operation_test.go b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/id_operation_test.go new file mode 100644 index 00000000000..fcf8529b81b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/id_operation_test.go @@ -0,0 +1,372 @@ +package apioperationpolicy + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &OperationId{} + +func TestNewOperationID(t *testing.T) { + id := NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "operationIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } + + if id.OperationId != "operationIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'OperationId'", id.OperationId, "operationIdValue") + } +} + +func TestFormatOperationID(t *testing.T) { + actual := NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "operationIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations/operationIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseOperationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OperationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations/operationIdValue", + Expected: &OperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + OperationId: "operationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations/operationIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOperationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestParseOperationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OperationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/oPeRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations/operationIdValue", + Expected: &OperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + OperationId: "operationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations/operationIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/oPeRaTiOnS/oPeRaTiOnIdVaLuE", + Expected: &OperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + OperationId: "oPeRaTiOnIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/oPeRaTiOnS/oPeRaTiOnIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOperationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestSegmentsForOperationId(t *testing.T) { + segments := OperationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("OperationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_createorupdate.go new file mode 100644 index 00000000000..3437b481d77 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_createorupdate.go @@ -0,0 +1,88 @@ +package apioperationpolicy + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c ApiOperationPolicyClient) CreateOrUpdate(ctx context.Context, id OperationId, input PolicyContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", 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 PolicyContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_delete.go b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_delete.go new file mode 100644 index 00000000000..1b77d06ed20 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_delete.go @@ -0,0 +1,76 @@ +package apioperationpolicy + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c ApiOperationPolicyClient) Delete(ctx context.Context, id OperationId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_get.go b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_get.go new file mode 100644 index 00000000000..53ce4e80d68 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_get.go @@ -0,0 +1,83 @@ +package apioperationpolicy + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyContract +} + +type GetOperationOptions struct { + Format *PolicyExportFormat +} + +func DefaultGetOperationOptions() GetOperationOptions { + return GetOperationOptions{} +} + +func (o GetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o GetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o GetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Format != nil { + out.Append("format", fmt.Sprintf("%v", *o.Format)) + } + return &out +} + +// Get ... +func (c ApiOperationPolicyClient) Get(ctx context.Context, id OperationId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", 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 PolicyContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_getentitytag.go new file mode 100644 index 00000000000..88da95a1537 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_getentitytag.go @@ -0,0 +1,47 @@ +package apioperationpolicy + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c ApiOperationPolicyClient) GetEntityTag(ctx context.Context, id OperationId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: fmt.Sprintf("%s/policies/policy", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_listbyoperation.go b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_listbyoperation.go new file mode 100644 index 00000000000..6368c593060 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_listbyoperation.go @@ -0,0 +1,105 @@ +package apioperationpolicy + +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 ListByOperationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PolicyContract +} + +type ListByOperationCompleteResult struct { + LatestHttpResponse *http.Response + Items []PolicyContract +} + +type ListByOperationCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByOperationCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByOperation ... +func (c ApiOperationPolicyClient) ListByOperation(ctx context.Context, id OperationId) (result ListByOperationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByOperationCustomPager{}, + Path: fmt.Sprintf("%s/policies", 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 *[]PolicyContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByOperationComplete retrieves all the results into a single object +func (c ApiOperationPolicyClient) ListByOperationComplete(ctx context.Context, id OperationId) (ListByOperationCompleteResult, error) { + return c.ListByOperationCompleteMatchingPredicate(ctx, id, PolicyContractOperationPredicate{}) +} + +// ListByOperationCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiOperationPolicyClient) ListByOperationCompleteMatchingPredicate(ctx context.Context, id OperationId, predicate PolicyContractOperationPredicate) (result ListByOperationCompleteResult, err error) { + items := make([]PolicyContract, 0) + + resp, err := c.ListByOperation(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByOperationCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_workspaceapioperationpolicycreateorupdate.go b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_workspaceapioperationpolicycreateorupdate.go new file mode 100644 index 00000000000..749273ac587 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_workspaceapioperationpolicycreateorupdate.go @@ -0,0 +1,88 @@ +package apioperationpolicy + +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 WorkspaceApiOperationPolicyCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyContract +} + +type WorkspaceApiOperationPolicyCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceApiOperationPolicyCreateOrUpdateOperationOptions() WorkspaceApiOperationPolicyCreateOrUpdateOperationOptions { + return WorkspaceApiOperationPolicyCreateOrUpdateOperationOptions{} +} + +func (o WorkspaceApiOperationPolicyCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceApiOperationPolicyCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiOperationPolicyCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceApiOperationPolicyCreateOrUpdate ... +func (c ApiOperationPolicyClient) WorkspaceApiOperationPolicyCreateOrUpdate(ctx context.Context, id ApiOperationId, input PolicyContract, options WorkspaceApiOperationPolicyCreateOrUpdateOperationOptions) (result WorkspaceApiOperationPolicyCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", 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 PolicyContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_workspaceapioperationpolicydelete.go b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_workspaceapioperationpolicydelete.go new file mode 100644 index 00000000000..47c3dded764 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_workspaceapioperationpolicydelete.go @@ -0,0 +1,76 @@ +package apioperationpolicy + +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 WorkspaceApiOperationPolicyDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type WorkspaceApiOperationPolicyDeleteOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceApiOperationPolicyDeleteOperationOptions() WorkspaceApiOperationPolicyDeleteOperationOptions { + return WorkspaceApiOperationPolicyDeleteOperationOptions{} +} + +func (o WorkspaceApiOperationPolicyDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceApiOperationPolicyDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiOperationPolicyDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceApiOperationPolicyDelete ... +func (c ApiOperationPolicyClient) WorkspaceApiOperationPolicyDelete(ctx context.Context, id ApiOperationId, options WorkspaceApiOperationPolicyDeleteOperationOptions) (result WorkspaceApiOperationPolicyDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_workspaceapioperationpolicyget.go b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_workspaceapioperationpolicyget.go new file mode 100644 index 00000000000..9395af3465a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_workspaceapioperationpolicyget.go @@ -0,0 +1,83 @@ +package apioperationpolicy + +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 WorkspaceApiOperationPolicyGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyContract +} + +type WorkspaceApiOperationPolicyGetOperationOptions struct { + Format *PolicyExportFormat +} + +func DefaultWorkspaceApiOperationPolicyGetOperationOptions() WorkspaceApiOperationPolicyGetOperationOptions { + return WorkspaceApiOperationPolicyGetOperationOptions{} +} + +func (o WorkspaceApiOperationPolicyGetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceApiOperationPolicyGetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiOperationPolicyGetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Format != nil { + out.Append("format", fmt.Sprintf("%v", *o.Format)) + } + return &out +} + +// WorkspaceApiOperationPolicyGet ... +func (c ApiOperationPolicyClient) WorkspaceApiOperationPolicyGet(ctx context.Context, id ApiOperationId, options WorkspaceApiOperationPolicyGetOperationOptions) (result WorkspaceApiOperationPolicyGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", 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 PolicyContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_workspaceapioperationpolicygetentitytag.go b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_workspaceapioperationpolicygetentitytag.go new file mode 100644 index 00000000000..84f2cfa29a7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_workspaceapioperationpolicygetentitytag.go @@ -0,0 +1,47 @@ +package apioperationpolicy + +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 WorkspaceApiOperationPolicyGetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceApiOperationPolicyGetEntityTag ... +func (c ApiOperationPolicyClient) WorkspaceApiOperationPolicyGetEntityTag(ctx context.Context, id ApiOperationId) (result WorkspaceApiOperationPolicyGetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: fmt.Sprintf("%s/policies/policy", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_workspaceapioperationpolicylistbyoperation.go b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_workspaceapioperationpolicylistbyoperation.go new file mode 100644 index 00000000000..f09ff195389 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/method_workspaceapioperationpolicylistbyoperation.go @@ -0,0 +1,105 @@ +package apioperationpolicy + +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 WorkspaceApiOperationPolicyListByOperationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PolicyContract +} + +type WorkspaceApiOperationPolicyListByOperationCompleteResult struct { + LatestHttpResponse *http.Response + Items []PolicyContract +} + +type WorkspaceApiOperationPolicyListByOperationCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceApiOperationPolicyListByOperationCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceApiOperationPolicyListByOperation ... +func (c ApiOperationPolicyClient) WorkspaceApiOperationPolicyListByOperation(ctx context.Context, id ApiOperationId) (result WorkspaceApiOperationPolicyListByOperationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &WorkspaceApiOperationPolicyListByOperationCustomPager{}, + Path: fmt.Sprintf("%s/policies", 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 *[]PolicyContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceApiOperationPolicyListByOperationComplete retrieves all the results into a single object +func (c ApiOperationPolicyClient) WorkspaceApiOperationPolicyListByOperationComplete(ctx context.Context, id ApiOperationId) (WorkspaceApiOperationPolicyListByOperationCompleteResult, error) { + return c.WorkspaceApiOperationPolicyListByOperationCompleteMatchingPredicate(ctx, id, PolicyContractOperationPredicate{}) +} + +// WorkspaceApiOperationPolicyListByOperationCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiOperationPolicyClient) WorkspaceApiOperationPolicyListByOperationCompleteMatchingPredicate(ctx context.Context, id ApiOperationId, predicate PolicyContractOperationPredicate) (result WorkspaceApiOperationPolicyListByOperationCompleteResult, err error) { + items := make([]PolicyContract, 0) + + resp, err := c.WorkspaceApiOperationPolicyListByOperation(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceApiOperationPolicyListByOperationCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationpolicy/model_policycontract.go b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/model_policycontract.go new file mode 100644 index 00000000000..4a0e709073f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/model_policycontract.go @@ -0,0 +1,11 @@ +package apioperationpolicy + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PolicyContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationpolicy/model_policycontractproperties.go b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/model_policycontractproperties.go new file mode 100644 index 00000000000..ec041034d70 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/model_policycontractproperties.go @@ -0,0 +1,9 @@ +package apioperationpolicy + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyContractProperties struct { + Format *PolicyContentFormat `json:"format,omitempty"` + Value string `json:"value"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationpolicy/predicates.go b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/predicates.go new file mode 100644 index 00000000000..a002c6c9c0d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/predicates.go @@ -0,0 +1,27 @@ +package apioperationpolicy + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PolicyContractOperationPredicate) Matches(input PolicyContract) 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/apimanagement/2024-05-01/apioperationpolicy/version.go b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/version.go new file mode 100644 index 00000000000..2ff7ac8dffa --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationpolicy/version.go @@ -0,0 +1,12 @@ +package apioperationpolicy + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apioperationpolicy/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationsbytag/README.md b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/README.md new file mode 100644 index 00000000000..870156b53a1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apioperationsbytag` Documentation + +The `apioperationsbytag` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apioperationsbytag" +``` + + +### Client Initialization + +```go +client := apioperationsbytag.NewApiOperationsByTagClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiOperationsByTagClient.OperationListByTags` + +```go +ctx := context.TODO() +id := apioperationsbytag.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +// alternatively `client.OperationListByTags(ctx, id, apioperationsbytag.DefaultOperationListByTagsOperationOptions())` can be used to do batched pagination +items, err := client.OperationListByTagsComplete(ctx, id, apioperationsbytag.DefaultOperationListByTagsOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/apioperationsbytag/client.go b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/client.go new file mode 100644 index 00000000000..26f8b7f55aa --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/client.go @@ -0,0 +1,26 @@ +package apioperationsbytag + +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 ApiOperationsByTagClient struct { + Client *resourcemanager.Client +} + +func NewApiOperationsByTagClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiOperationsByTagClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apioperationsbytag", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiOperationsByTagClient: %+v", err) + } + + return &ApiOperationsByTagClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationsbytag/constants.go b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/constants.go new file mode 100644 index 00000000000..aede5fb73f8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/constants.go @@ -0,0 +1,192 @@ +package apioperationsbytag + +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 ApiType string + +const ( + ApiTypeGraphql ApiType = "graphql" + ApiTypeGrpc ApiType = "grpc" + ApiTypeHTTP ApiType = "http" + ApiTypeOdata ApiType = "odata" + ApiTypeSoap ApiType = "soap" + ApiTypeWebsocket ApiType = "websocket" +) + +func PossibleValuesForApiType() []string { + return []string{ + string(ApiTypeGraphql), + string(ApiTypeGrpc), + string(ApiTypeHTTP), + string(ApiTypeOdata), + string(ApiTypeSoap), + string(ApiTypeWebsocket), + } +} + +func (s *ApiType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseApiType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseApiType(input string) (*ApiType, error) { + vals := map[string]ApiType{ + "graphql": ApiTypeGraphql, + "grpc": ApiTypeGrpc, + "http": ApiTypeHTTP, + "odata": ApiTypeOdata, + "soap": ApiTypeSoap, + "websocket": ApiTypeWebsocket, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ApiType(input) + return &out, nil +} + +type BearerTokenSendingMethods string + +const ( + BearerTokenSendingMethodsAuthorizationHeader BearerTokenSendingMethods = "authorizationHeader" + BearerTokenSendingMethodsQuery BearerTokenSendingMethods = "query" +) + +func PossibleValuesForBearerTokenSendingMethods() []string { + return []string{ + string(BearerTokenSendingMethodsAuthorizationHeader), + string(BearerTokenSendingMethodsQuery), + } +} + +func (s *BearerTokenSendingMethods) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBearerTokenSendingMethods(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBearerTokenSendingMethods(input string) (*BearerTokenSendingMethods, error) { + vals := map[string]BearerTokenSendingMethods{ + "authorizationheader": BearerTokenSendingMethodsAuthorizationHeader, + "query": BearerTokenSendingMethodsQuery, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BearerTokenSendingMethods(input) + return &out, nil +} + +type ProductState string + +const ( + ProductStateNotPublished ProductState = "notPublished" + ProductStatePublished ProductState = "published" +) + +func PossibleValuesForProductState() []string { + return []string{ + string(ProductStateNotPublished), + string(ProductStatePublished), + } +} + +func (s *ProductState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProductState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProductState(input string) (*ProductState, error) { + vals := map[string]ProductState{ + "notpublished": ProductStateNotPublished, + "published": ProductStatePublished, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProductState(input) + return &out, nil +} + +type Protocol string + +const ( + ProtocolHTTP Protocol = "http" + ProtocolHTTPS Protocol = "https" + ProtocolWs Protocol = "ws" + ProtocolWss Protocol = "wss" +) + +func PossibleValuesForProtocol() []string { + return []string{ + string(ProtocolHTTP), + string(ProtocolHTTPS), + string(ProtocolWs), + string(ProtocolWss), + } +} + +func (s *Protocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProtocol(input string) (*Protocol, error) { + vals := map[string]Protocol{ + "http": ProtocolHTTP, + "https": ProtocolHTTPS, + "ws": ProtocolWs, + "wss": ProtocolWss, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Protocol(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationsbytag/id_api.go b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/id_api.go new file mode 100644 index 00000000000..5897ef0aafc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/id_api.go @@ -0,0 +1,139 @@ +package apioperationsbytag + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiId{}) +} + +var _ resourceids.ResourceId = &ApiId{} + +// ApiId is a struct representing the Resource ID for a Api +type ApiId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string +} + +// NewApiID returns a new ApiId struct +func NewApiID(subscriptionId string, resourceGroupName string, serviceName string, apiId string) ApiId { + return ApiId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + } +} + +// ParseApiID parses 'input' into a ApiId +func ParseApiID(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiIDInsensitively parses 'input' case-insensitively into a ApiId +// note: this method should only be used for API response data and not user input +func ParseApiIDInsensitively(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + return nil +} + +// ValidateApiID checks that 'input' can be parsed as a Api ID +func ValidateApiID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api ID +func (id ApiId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api ID +func (id ApiId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + } +} + +// String returns a human-readable description of this Api ID +func (id ApiId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + } + return fmt.Sprintf("Api (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationsbytag/id_api_test.go b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/id_api_test.go new file mode 100644 index 00000000000..63cd78a7c83 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/id_api_test.go @@ -0,0 +1,327 @@ +package apioperationsbytag + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiId{} + +func TestNewApiID(t *testing.T) { + id := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } +} + +func TestFormatApiID(t *testing.T) { + actual := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestParseApiIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestSegmentsForApiId(t *testing.T) { + segments := ApiId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationsbytag/method_operationlistbytags.go b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/method_operationlistbytags.go new file mode 100644 index 00000000000..2a37906b22f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/method_operationlistbytags.go @@ -0,0 +1,145 @@ +package apioperationsbytag + +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 OperationListByTagsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TagResourceContract +} + +type OperationListByTagsCompleteResult struct { + LatestHttpResponse *http.Response + Items []TagResourceContract +} + +type OperationListByTagsOperationOptions struct { + Filter *string + IncludeNotTaggedOperations *bool + Skip *int64 + Top *int64 +} + +func DefaultOperationListByTagsOperationOptions() OperationListByTagsOperationOptions { + return OperationListByTagsOperationOptions{} +} + +func (o OperationListByTagsOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o OperationListByTagsOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o OperationListByTagsOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.IncludeNotTaggedOperations != nil { + out.Append("includeNotTaggedOperations", fmt.Sprintf("%v", *o.IncludeNotTaggedOperations)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type OperationListByTagsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *OperationListByTagsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// OperationListByTags ... +func (c ApiOperationsByTagClient) OperationListByTags(ctx context.Context, id ApiId, options OperationListByTagsOperationOptions) (result OperationListByTagsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &OperationListByTagsCustomPager{}, + Path: fmt.Sprintf("%s/operationsByTags", 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 *[]TagResourceContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// OperationListByTagsComplete retrieves all the results into a single object +func (c ApiOperationsByTagClient) OperationListByTagsComplete(ctx context.Context, id ApiId, options OperationListByTagsOperationOptions) (OperationListByTagsCompleteResult, error) { + return c.OperationListByTagsCompleteMatchingPredicate(ctx, id, options, TagResourceContractOperationPredicate{}) +} + +// OperationListByTagsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiOperationsByTagClient) OperationListByTagsCompleteMatchingPredicate(ctx context.Context, id ApiId, options OperationListByTagsOperationOptions, predicate TagResourceContractOperationPredicate) (result OperationListByTagsCompleteResult, err error) { + items := make([]TagResourceContract, 0) + + resp, err := c.OperationListByTags(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = OperationListByTagsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_apicontactinformation.go b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_apicontactinformation.go new file mode 100644 index 00000000000..2686e16d1aa --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_apicontactinformation.go @@ -0,0 +1,10 @@ +package apioperationsbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiContactInformation struct { + Email *string `json:"email,omitempty"` + Name *string `json:"name,omitempty"` + Url *string `json:"url,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_apilicenseinformation.go b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_apilicenseinformation.go new file mode 100644 index 00000000000..9a4c056116d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_apilicenseinformation.go @@ -0,0 +1,9 @@ +package apioperationsbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiLicenseInformation struct { + Name *string `json:"name,omitempty"` + Url *string `json:"url,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_apitagresourcecontractproperties.go b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_apitagresourcecontractproperties.go new file mode 100644 index 00000000000..29865d37c08 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_apitagresourcecontractproperties.go @@ -0,0 +1,27 @@ +package apioperationsbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiTagResourceContractProperties struct { + ApiRevision *string `json:"apiRevision,omitempty"` + ApiRevisionDescription *string `json:"apiRevisionDescription,omitempty"` + ApiVersion *string `json:"apiVersion,omitempty"` + ApiVersionDescription *string `json:"apiVersionDescription,omitempty"` + ApiVersionSetId *string `json:"apiVersionSetId,omitempty"` + AuthenticationSettings *AuthenticationSettingsContract `json:"authenticationSettings,omitempty"` + Contact *ApiContactInformation `json:"contact,omitempty"` + Description *string `json:"description,omitempty"` + Id *string `json:"id,omitempty"` + IsCurrent *bool `json:"isCurrent,omitempty"` + IsOnline *bool `json:"isOnline,omitempty"` + License *ApiLicenseInformation `json:"license,omitempty"` + Name *string `json:"name,omitempty"` + Path *string `json:"path,omitempty"` + Protocols *[]Protocol `json:"protocols,omitempty"` + ServiceUrl *string `json:"serviceUrl,omitempty"` + SubscriptionKeyParameterNames *SubscriptionKeyParameterNamesContract `json:"subscriptionKeyParameterNames,omitempty"` + SubscriptionRequired *bool `json:"subscriptionRequired,omitempty"` + TermsOfServiceUrl *string `json:"termsOfServiceUrl,omitempty"` + Type *ApiType `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_authenticationsettingscontract.go b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_authenticationsettingscontract.go new file mode 100644 index 00000000000..642c32ede00 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_authenticationsettingscontract.go @@ -0,0 +1,11 @@ +package apioperationsbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthenticationSettingsContract struct { + OAuth2 *OAuth2AuthenticationSettingsContract `json:"oAuth2,omitempty"` + OAuth2AuthenticationSettings *[]OAuth2AuthenticationSettingsContract `json:"oAuth2AuthenticationSettings,omitempty"` + Openid *OpenIdAuthenticationSettingsContract `json:"openid,omitempty"` + OpenidAuthenticationSettings *[]OpenIdAuthenticationSettingsContract `json:"openidAuthenticationSettings,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_oauth2authenticationsettingscontract.go b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_oauth2authenticationsettingscontract.go new file mode 100644 index 00000000000..4b4e82a3809 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_oauth2authenticationsettingscontract.go @@ -0,0 +1,9 @@ +package apioperationsbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OAuth2AuthenticationSettingsContract struct { + AuthorizationServerId *string `json:"authorizationServerId,omitempty"` + Scope *string `json:"scope,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_openidauthenticationsettingscontract.go b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_openidauthenticationsettingscontract.go new file mode 100644 index 00000000000..ba6e89d9775 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_openidauthenticationsettingscontract.go @@ -0,0 +1,9 @@ +package apioperationsbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OpenIdAuthenticationSettingsContract struct { + BearerTokenSendingMethods *[]BearerTokenSendingMethods `json:"bearerTokenSendingMethods,omitempty"` + OpenidProviderId *string `json:"openidProviderId,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_operationtagresourcecontractproperties.go b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_operationtagresourcecontractproperties.go new file mode 100644 index 00000000000..53c84716394 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_operationtagresourcecontractproperties.go @@ -0,0 +1,15 @@ +package apioperationsbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationTagResourceContractProperties struct { + ApiName *string `json:"apiName,omitempty"` + ApiRevision *string `json:"apiRevision,omitempty"` + ApiVersion *string `json:"apiVersion,omitempty"` + Description *string `json:"description,omitempty"` + Id *string `json:"id,omitempty"` + Method *string `json:"method,omitempty"` + Name *string `json:"name,omitempty"` + UrlTemplate *string `json:"urlTemplate,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_producttagresourcecontractproperties.go b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_producttagresourcecontractproperties.go new file mode 100644 index 00000000000..17955a4143b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_producttagresourcecontractproperties.go @@ -0,0 +1,15 @@ +package apioperationsbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductTagResourceContractProperties struct { + ApprovalRequired *bool `json:"approvalRequired,omitempty"` + Description *string `json:"description,omitempty"` + Id *string `json:"id,omitempty"` + Name string `json:"name"` + State *ProductState `json:"state,omitempty"` + SubscriptionRequired *bool `json:"subscriptionRequired,omitempty"` + SubscriptionsLimit *int64 `json:"subscriptionsLimit,omitempty"` + Terms *string `json:"terms,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_subscriptionkeyparameternamescontract.go b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_subscriptionkeyparameternamescontract.go new file mode 100644 index 00000000000..a03149cfb3f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_subscriptionkeyparameternamescontract.go @@ -0,0 +1,9 @@ +package apioperationsbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionKeyParameterNamesContract struct { + Header *string `json:"header,omitempty"` + Query *string `json:"query,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_tagresourcecontract.go b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_tagresourcecontract.go new file mode 100644 index 00000000000..45e2bd1c6f2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_tagresourcecontract.go @@ -0,0 +1,11 @@ +package apioperationsbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagResourceContract struct { + Api *ApiTagResourceContractProperties `json:"api,omitempty"` + Operation *OperationTagResourceContractProperties `json:"operation,omitempty"` + Product *ProductTagResourceContractProperties `json:"product,omitempty"` + Tag TagTagResourceContractProperties `json:"tag"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_tagtagresourcecontractproperties.go b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_tagtagresourcecontractproperties.go new file mode 100644 index 00000000000..3c99b045839 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/model_tagtagresourcecontractproperties.go @@ -0,0 +1,9 @@ +package apioperationsbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagTagResourceContractProperties struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationsbytag/predicates.go b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/predicates.go new file mode 100644 index 00000000000..4215375cb88 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/predicates.go @@ -0,0 +1,12 @@ +package apioperationsbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagResourceContractOperationPredicate struct { +} + +func (p TagResourceContractOperationPredicate) Matches(input TagResourceContract) bool { + + return true +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationsbytag/version.go b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/version.go new file mode 100644 index 00000000000..47b1f102919 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationsbytag/version.go @@ -0,0 +1,12 @@ +package apioperationsbytag + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apioperationsbytag/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationtag/README.md b/resource-manager/apimanagement/2024-05-01/apioperationtag/README.md new file mode 100644 index 00000000000..601c011ada0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationtag/README.md @@ -0,0 +1,101 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apioperationtag` Documentation + +The `apioperationtag` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apioperationtag" +``` + + +### Client Initialization + +```go +client := apioperationtag.NewApiOperationTagClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiOperationTagClient.TagAssignToOperation` + +```go +ctx := context.TODO() +id := apioperationtag.NewOperationTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "operationIdValue", "tagIdValue") + +read, err := client.TagAssignToOperation(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiOperationTagClient.TagDetachFromOperation` + +```go +ctx := context.TODO() +id := apioperationtag.NewOperationTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "operationIdValue", "tagIdValue") + +read, err := client.TagDetachFromOperation(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiOperationTagClient.TagGetByOperation` + +```go +ctx := context.TODO() +id := apioperationtag.NewOperationTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "operationIdValue", "tagIdValue") + +read, err := client.TagGetByOperation(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiOperationTagClient.TagGetEntityStateByOperation` + +```go +ctx := context.TODO() +id := apioperationtag.NewOperationTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "operationIdValue", "tagIdValue") + +read, err := client.TagGetEntityStateByOperation(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiOperationTagClient.TagListByOperation` + +```go +ctx := context.TODO() +id := apioperationtag.NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "operationIdValue") + +// alternatively `client.TagListByOperation(ctx, id, apioperationtag.DefaultTagListByOperationOperationOptions())` can be used to do batched pagination +items, err := client.TagListByOperationComplete(ctx, id, apioperationtag.DefaultTagListByOperationOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/apioperationtag/client.go b/resource-manager/apimanagement/2024-05-01/apioperationtag/client.go new file mode 100644 index 00000000000..6f14f25474c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationtag/client.go @@ -0,0 +1,26 @@ +package apioperationtag + +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 ApiOperationTagClient struct { + Client *resourcemanager.Client +} + +func NewApiOperationTagClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiOperationTagClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apioperationtag", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiOperationTagClient: %+v", err) + } + + return &ApiOperationTagClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationtag/id_operation.go b/resource-manager/apimanagement/2024-05-01/apioperationtag/id_operation.go new file mode 100644 index 00000000000..efa4b494f53 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationtag/id_operation.go @@ -0,0 +1,148 @@ +package apioperationtag + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&OperationId{}) +} + +var _ resourceids.ResourceId = &OperationId{} + +// OperationId is a struct representing the Resource ID for a Operation +type OperationId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string + OperationId string +} + +// NewOperationID returns a new OperationId struct +func NewOperationID(subscriptionId string, resourceGroupName string, serviceName string, apiId string, operationId string) OperationId { + return OperationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + OperationId: operationId, + } +} + +// ParseOperationID parses 'input' into a OperationId +func ParseOperationID(input string) (*OperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&OperationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OperationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseOperationIDInsensitively parses 'input' case-insensitively into a OperationId +// note: this method should only be used for API response data and not user input +func ParseOperationIDInsensitively(input string) (*OperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&OperationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OperationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *OperationId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + if id.OperationId, ok = input.Parsed["operationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "operationId", input) + } + + return nil +} + +// ValidateOperationID checks that 'input' can be parsed as a Operation ID +func ValidateOperationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseOperationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Operation ID +func (id OperationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s/operations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId, id.OperationId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Operation ID +func (id OperationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + resourceids.StaticSegment("staticOperations", "operations", "operations"), + resourceids.UserSpecifiedSegment("operationId", "operationIdValue"), + } +} + +// String returns a human-readable description of this Operation ID +func (id OperationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + fmt.Sprintf("Operation: %q", id.OperationId), + } + return fmt.Sprintf("Operation (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationtag/id_operation_test.go b/resource-manager/apimanagement/2024-05-01/apioperationtag/id_operation_test.go new file mode 100644 index 00000000000..ea5c6982a16 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationtag/id_operation_test.go @@ -0,0 +1,372 @@ +package apioperationtag + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &OperationId{} + +func TestNewOperationID(t *testing.T) { + id := NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "operationIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } + + if id.OperationId != "operationIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'OperationId'", id.OperationId, "operationIdValue") + } +} + +func TestFormatOperationID(t *testing.T) { + actual := NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "operationIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations/operationIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseOperationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OperationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations/operationIdValue", + Expected: &OperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + OperationId: "operationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations/operationIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOperationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestParseOperationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OperationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/oPeRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations/operationIdValue", + Expected: &OperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + OperationId: "operationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations/operationIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/oPeRaTiOnS/oPeRaTiOnIdVaLuE", + Expected: &OperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + OperationId: "oPeRaTiOnIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/oPeRaTiOnS/oPeRaTiOnIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOperationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestSegmentsForOperationId(t *testing.T) { + segments := OperationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("OperationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationtag/id_operationtag.go b/resource-manager/apimanagement/2024-05-01/apioperationtag/id_operationtag.go new file mode 100644 index 00000000000..278b58eaf30 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationtag/id_operationtag.go @@ -0,0 +1,157 @@ +package apioperationtag + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&OperationTagId{}) +} + +var _ resourceids.ResourceId = &OperationTagId{} + +// OperationTagId is a struct representing the Resource ID for a Operation Tag +type OperationTagId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string + OperationId string + TagId string +} + +// NewOperationTagID returns a new OperationTagId struct +func NewOperationTagID(subscriptionId string, resourceGroupName string, serviceName string, apiId string, operationId string, tagId string) OperationTagId { + return OperationTagId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + OperationId: operationId, + TagId: tagId, + } +} + +// ParseOperationTagID parses 'input' into a OperationTagId +func ParseOperationTagID(input string) (*OperationTagId, error) { + parser := resourceids.NewParserFromResourceIdType(&OperationTagId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OperationTagId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseOperationTagIDInsensitively parses 'input' case-insensitively into a OperationTagId +// note: this method should only be used for API response data and not user input +func ParseOperationTagIDInsensitively(input string) (*OperationTagId, error) { + parser := resourceids.NewParserFromResourceIdType(&OperationTagId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OperationTagId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *OperationTagId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + if id.OperationId, ok = input.Parsed["operationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "operationId", input) + } + + if id.TagId, ok = input.Parsed["tagId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagId", input) + } + + return nil +} + +// ValidateOperationTagID checks that 'input' can be parsed as a Operation Tag ID +func ValidateOperationTagID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseOperationTagID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Operation Tag ID +func (id OperationTagId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s/operations/%s/tags/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId, id.OperationId, id.TagId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Operation Tag ID +func (id OperationTagId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + resourceids.StaticSegment("staticOperations", "operations", "operations"), + resourceids.UserSpecifiedSegment("operationId", "operationIdValue"), + resourceids.StaticSegment("staticTags", "tags", "tags"), + resourceids.UserSpecifiedSegment("tagId", "tagIdValue"), + } +} + +// String returns a human-readable description of this Operation Tag ID +func (id OperationTagId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + fmt.Sprintf("Operation: %q", id.OperationId), + fmt.Sprintf("Tag: %q", id.TagId), + } + return fmt.Sprintf("Operation Tag (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationtag/id_operationtag_test.go b/resource-manager/apimanagement/2024-05-01/apioperationtag/id_operationtag_test.go new file mode 100644 index 00000000000..1401c95e6cc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationtag/id_operationtag_test.go @@ -0,0 +1,417 @@ +package apioperationtag + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &OperationTagId{} + +func TestNewOperationTagID(t *testing.T) { + id := NewOperationTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "operationIdValue", "tagIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } + + if id.OperationId != "operationIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'OperationId'", id.OperationId, "operationIdValue") + } + + if id.TagId != "tagIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'TagId'", id.TagId, "tagIdValue") + } +} + +func TestFormatOperationTagID(t *testing.T) { + actual := NewOperationTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "operationIdValue", "tagIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations/operationIdValue/tags/tagIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseOperationTagID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OperationTagId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations/operationIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations/operationIdValue/tags", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations/operationIdValue/tags/tagIdValue", + Expected: &OperationTagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + OperationId: "operationIdValue", + TagId: "tagIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations/operationIdValue/tags/tagIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOperationTagID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + } +} + +func TestParseOperationTagIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OperationTagId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/oPeRaTiOnS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations/operationIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/oPeRaTiOnS/oPeRaTiOnIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations/operationIdValue/tags", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/oPeRaTiOnS/oPeRaTiOnIdVaLuE/tAgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations/operationIdValue/tags/tagIdValue", + Expected: &OperationTagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + OperationId: "operationIdValue", + TagId: "tagIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/operations/operationIdValue/tags/tagIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/oPeRaTiOnS/oPeRaTiOnIdVaLuE/tAgS/tAgIdVaLuE", + Expected: &OperationTagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + OperationId: "oPeRaTiOnIdVaLuE", + TagId: "tAgIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/oPeRaTiOnS/oPeRaTiOnIdVaLuE/tAgS/tAgIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOperationTagIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + } +} + +func TestSegmentsForOperationTagId(t *testing.T) { + segments := OperationTagId{}.Segments() + if len(segments) == 0 { + t.Fatalf("OperationTagId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationtag/method_tagassigntooperation.go b/resource-manager/apimanagement/2024-05-01/apioperationtag/method_tagassigntooperation.go new file mode 100644 index 00000000000..ee4d3b0dbb0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationtag/method_tagassigntooperation.go @@ -0,0 +1,55 @@ +package apioperationtag + +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 TagAssignToOperationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TagContract +} + +// TagAssignToOperation ... +func (c ApiOperationTagClient) TagAssignToOperation(ctx context.Context, id OperationTagId) (result TagAssignToOperationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model TagContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationtag/method_tagdetachfromoperation.go b/resource-manager/apimanagement/2024-05-01/apioperationtag/method_tagdetachfromoperation.go new file mode 100644 index 00000000000..b49f13cabd9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationtag/method_tagdetachfromoperation.go @@ -0,0 +1,47 @@ +package apioperationtag + +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 TagDetachFromOperationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// TagDetachFromOperation ... +func (c ApiOperationTagClient) TagDetachFromOperation(ctx context.Context, id OperationTagId) (result TagDetachFromOperationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationtag/method_taggetbyoperation.go b/resource-manager/apimanagement/2024-05-01/apioperationtag/method_taggetbyoperation.go new file mode 100644 index 00000000000..7448f9ee27a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationtag/method_taggetbyoperation.go @@ -0,0 +1,54 @@ +package apioperationtag + +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 TagGetByOperationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TagContract +} + +// TagGetByOperation ... +func (c ApiOperationTagClient) TagGetByOperation(ctx context.Context, id OperationTagId) (result TagGetByOperationOperationResponse, 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 TagContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationtag/method_taggetentitystatebyoperation.go b/resource-manager/apimanagement/2024-05-01/apioperationtag/method_taggetentitystatebyoperation.go new file mode 100644 index 00000000000..066af82b190 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationtag/method_taggetentitystatebyoperation.go @@ -0,0 +1,46 @@ +package apioperationtag + +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 TagGetEntityStateByOperationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// TagGetEntityStateByOperation ... +func (c ApiOperationTagClient) TagGetEntityStateByOperation(ctx context.Context, id OperationTagId) (result TagGetEntityStateByOperationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationtag/method_taglistbyoperation.go b/resource-manager/apimanagement/2024-05-01/apioperationtag/method_taglistbyoperation.go new file mode 100644 index 00000000000..f68870a2587 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationtag/method_taglistbyoperation.go @@ -0,0 +1,141 @@ +package apioperationtag + +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 TagListByOperationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TagContract +} + +type TagListByOperationCompleteResult struct { + LatestHttpResponse *http.Response + Items []TagContract +} + +type TagListByOperationOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultTagListByOperationOperationOptions() TagListByOperationOperationOptions { + return TagListByOperationOperationOptions{} +} + +func (o TagListByOperationOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o TagListByOperationOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o TagListByOperationOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type TagListByOperationCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *TagListByOperationCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// TagListByOperation ... +func (c ApiOperationTagClient) TagListByOperation(ctx context.Context, id OperationId, options TagListByOperationOperationOptions) (result TagListByOperationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &TagListByOperationCustomPager{}, + Path: fmt.Sprintf("%s/tags", 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 *[]TagContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// TagListByOperationComplete retrieves all the results into a single object +func (c ApiOperationTagClient) TagListByOperationComplete(ctx context.Context, id OperationId, options TagListByOperationOperationOptions) (TagListByOperationCompleteResult, error) { + return c.TagListByOperationCompleteMatchingPredicate(ctx, id, options, TagContractOperationPredicate{}) +} + +// TagListByOperationCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiOperationTagClient) TagListByOperationCompleteMatchingPredicate(ctx context.Context, id OperationId, options TagListByOperationOperationOptions, predicate TagContractOperationPredicate) (result TagListByOperationCompleteResult, err error) { + items := make([]TagContract, 0) + + resp, err := c.TagListByOperation(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = TagListByOperationCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationtag/model_tagcontract.go b/resource-manager/apimanagement/2024-05-01/apioperationtag/model_tagcontract.go new file mode 100644 index 00000000000..def50a679a1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationtag/model_tagcontract.go @@ -0,0 +1,11 @@ +package apioperationtag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *TagContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationtag/model_tagcontractproperties.go b/resource-manager/apimanagement/2024-05-01/apioperationtag/model_tagcontractproperties.go new file mode 100644 index 00000000000..d4fd365e5f6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationtag/model_tagcontractproperties.go @@ -0,0 +1,8 @@ +package apioperationtag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagContractProperties struct { + DisplayName string `json:"displayName"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apioperationtag/predicates.go b/resource-manager/apimanagement/2024-05-01/apioperationtag/predicates.go new file mode 100644 index 00000000000..84e8e1e9330 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationtag/predicates.go @@ -0,0 +1,27 @@ +package apioperationtag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p TagContractOperationPredicate) Matches(input TagContract) 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/apimanagement/2024-05-01/apioperationtag/version.go b/resource-manager/apimanagement/2024-05-01/apioperationtag/version.go new file mode 100644 index 00000000000..839f7acd78d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apioperationtag/version.go @@ -0,0 +1,12 @@ +package apioperationtag + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apioperationtag/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apipolicy/README.md b/resource-manager/apimanagement/2024-05-01/apipolicy/README.md new file mode 100644 index 00000000000..354101348c7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apipolicy/README.md @@ -0,0 +1,192 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apipolicy` Documentation + +The `apipolicy` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apipolicy" +``` + + +### Client Initialization + +```go +client := apipolicy.NewApiPolicyClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiPolicyClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := apipolicy.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +payload := apipolicy.PolicyContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, apipolicy.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiPolicyClient.Delete` + +```go +ctx := context.TODO() +id := apipolicy.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +read, err := client.Delete(ctx, id, apipolicy.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiPolicyClient.Get` + +```go +ctx := context.TODO() +id := apipolicy.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +read, err := client.Get(ctx, id, apipolicy.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiPolicyClient.GetEntityTag` + +```go +ctx := context.TODO() +id := apipolicy.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiPolicyClient.ListByApi` + +```go +ctx := context.TODO() +id := apipolicy.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +// alternatively `client.ListByApi(ctx, id)` can be used to do batched pagination +items, err := client.ListByApiComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ApiPolicyClient.WorkspaceApiPolicyCreateOrUpdate` + +```go +ctx := context.TODO() +id := apipolicy.NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue") + +payload := apipolicy.PolicyContract{ + // ... +} + + +read, err := client.WorkspaceApiPolicyCreateOrUpdate(ctx, id, payload, apipolicy.DefaultWorkspaceApiPolicyCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiPolicyClient.WorkspaceApiPolicyDelete` + +```go +ctx := context.TODO() +id := apipolicy.NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue") + +read, err := client.WorkspaceApiPolicyDelete(ctx, id, apipolicy.DefaultWorkspaceApiPolicyDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiPolicyClient.WorkspaceApiPolicyGet` + +```go +ctx := context.TODO() +id := apipolicy.NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue") + +read, err := client.WorkspaceApiPolicyGet(ctx, id, apipolicy.DefaultWorkspaceApiPolicyGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiPolicyClient.WorkspaceApiPolicyGetEntityTag` + +```go +ctx := context.TODO() +id := apipolicy.NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue") + +read, err := client.WorkspaceApiPolicyGetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiPolicyClient.WorkspaceApiPolicyListByApi` + +```go +ctx := context.TODO() +id := apipolicy.NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue") + +// alternatively `client.WorkspaceApiPolicyListByApi(ctx, id)` can be used to do batched pagination +items, err := client.WorkspaceApiPolicyListByApiComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/apipolicy/client.go b/resource-manager/apimanagement/2024-05-01/apipolicy/client.go new file mode 100644 index 00000000000..84c3dfec8c9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apipolicy/client.go @@ -0,0 +1,26 @@ +package apipolicy + +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 ApiPolicyClient struct { + Client *resourcemanager.Client +} + +func NewApiPolicyClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiPolicyClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apipolicy", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiPolicyClient: %+v", err) + } + + return &ApiPolicyClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apipolicy/constants.go b/resource-manager/apimanagement/2024-05-01/apipolicy/constants.go new file mode 100644 index 00000000000..3a402942dd8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apipolicy/constants.go @@ -0,0 +1,98 @@ +package apipolicy + +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 PolicyContentFormat string + +const ( + PolicyContentFormatRawxml PolicyContentFormat = "rawxml" + PolicyContentFormatRawxmlNegativelink PolicyContentFormat = "rawxml-link" + PolicyContentFormatXml PolicyContentFormat = "xml" + PolicyContentFormatXmlNegativelink PolicyContentFormat = "xml-link" +) + +func PossibleValuesForPolicyContentFormat() []string { + return []string{ + string(PolicyContentFormatRawxml), + string(PolicyContentFormatRawxmlNegativelink), + string(PolicyContentFormatXml), + string(PolicyContentFormatXmlNegativelink), + } +} + +func (s *PolicyContentFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePolicyContentFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePolicyContentFormat(input string) (*PolicyContentFormat, error) { + vals := map[string]PolicyContentFormat{ + "rawxml": PolicyContentFormatRawxml, + "rawxml-link": PolicyContentFormatRawxmlNegativelink, + "xml": PolicyContentFormatXml, + "xml-link": PolicyContentFormatXmlNegativelink, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyContentFormat(input) + return &out, nil +} + +type PolicyExportFormat string + +const ( + PolicyExportFormatRawxml PolicyExportFormat = "rawxml" + PolicyExportFormatXml PolicyExportFormat = "xml" +) + +func PossibleValuesForPolicyExportFormat() []string { + return []string{ + string(PolicyExportFormatRawxml), + string(PolicyExportFormatXml), + } +} + +func (s *PolicyExportFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePolicyExportFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePolicyExportFormat(input string) (*PolicyExportFormat, error) { + vals := map[string]PolicyExportFormat{ + "rawxml": PolicyExportFormatRawxml, + "xml": PolicyExportFormatXml, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyExportFormat(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apipolicy/id_api.go b/resource-manager/apimanagement/2024-05-01/apipolicy/id_api.go new file mode 100644 index 00000000000..8423eae7bd7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apipolicy/id_api.go @@ -0,0 +1,139 @@ +package apipolicy + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiId{}) +} + +var _ resourceids.ResourceId = &ApiId{} + +// ApiId is a struct representing the Resource ID for a Api +type ApiId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string +} + +// NewApiID returns a new ApiId struct +func NewApiID(subscriptionId string, resourceGroupName string, serviceName string, apiId string) ApiId { + return ApiId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + } +} + +// ParseApiID parses 'input' into a ApiId +func ParseApiID(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiIDInsensitively parses 'input' case-insensitively into a ApiId +// note: this method should only be used for API response data and not user input +func ParseApiIDInsensitively(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + return nil +} + +// ValidateApiID checks that 'input' can be parsed as a Api ID +func ValidateApiID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api ID +func (id ApiId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api ID +func (id ApiId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + } +} + +// String returns a human-readable description of this Api ID +func (id ApiId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + } + return fmt.Sprintf("Api (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apipolicy/id_api_test.go b/resource-manager/apimanagement/2024-05-01/apipolicy/id_api_test.go new file mode 100644 index 00000000000..f8f28cb05d0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apipolicy/id_api_test.go @@ -0,0 +1,327 @@ +package apipolicy + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiId{} + +func TestNewApiID(t *testing.T) { + id := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } +} + +func TestFormatApiID(t *testing.T) { + actual := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestParseApiIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestSegmentsForApiId(t *testing.T) { + segments := ApiId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apipolicy/id_workspaceapi.go b/resource-manager/apimanagement/2024-05-01/apipolicy/id_workspaceapi.go new file mode 100644 index 00000000000..a7710bb2ef5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apipolicy/id_workspaceapi.go @@ -0,0 +1,148 @@ +package apipolicy + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceApiId{}) +} + +var _ resourceids.ResourceId = &WorkspaceApiId{} + +// WorkspaceApiId is a struct representing the Resource ID for a Workspace Api +type WorkspaceApiId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + ApiId string +} + +// NewWorkspaceApiID returns a new WorkspaceApiId struct +func NewWorkspaceApiID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, apiId string) WorkspaceApiId { + return WorkspaceApiId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + ApiId: apiId, + } +} + +// ParseWorkspaceApiID parses 'input' into a WorkspaceApiId +func ParseWorkspaceApiID(input string) (*WorkspaceApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceApiId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceApiIDInsensitively parses 'input' case-insensitively into a WorkspaceApiId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceApiIDInsensitively(input string) (*WorkspaceApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceApiId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceApiId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + return nil +} + +// ValidateWorkspaceApiID checks that 'input' can be parsed as a Workspace Api ID +func ValidateWorkspaceApiID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceApiID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Api ID +func (id WorkspaceApiId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/apis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.ApiId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Api ID +func (id WorkspaceApiId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + } +} + +// String returns a human-readable description of this Workspace Api ID +func (id WorkspaceApiId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Api: %q", id.ApiId), + } + return fmt.Sprintf("Workspace Api (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apipolicy/id_workspaceapi_test.go b/resource-manager/apimanagement/2024-05-01/apipolicy/id_workspaceapi_test.go new file mode 100644 index 00000000000..a555faff446 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apipolicy/id_workspaceapi_test.go @@ -0,0 +1,372 @@ +package apipolicy + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceApiId{} + +func TestNewWorkspaceApiID(t *testing.T) { + id := NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } +} + +func TestFormatWorkspaceApiID(t *testing.T) { + actual := NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceApiID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue", + Expected: &WorkspaceApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceApiID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestParseWorkspaceApiIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue", + Expected: &WorkspaceApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE", + Expected: &WorkspaceApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + ApiId: "aPiIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceApiIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestSegmentsForWorkspaceApiId(t *testing.T) { + segments := WorkspaceApiId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceApiId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apipolicy/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/apipolicy/method_createorupdate.go new file mode 100644 index 00000000000..eeaf614e85b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apipolicy/method_createorupdate.go @@ -0,0 +1,88 @@ +package apipolicy + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c ApiPolicyClient) CreateOrUpdate(ctx context.Context, id ApiId, input PolicyContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", 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 PolicyContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apipolicy/method_delete.go b/resource-manager/apimanagement/2024-05-01/apipolicy/method_delete.go new file mode 100644 index 00000000000..ee63586a23e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apipolicy/method_delete.go @@ -0,0 +1,76 @@ +package apipolicy + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c ApiPolicyClient) Delete(ctx context.Context, id ApiId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apipolicy/method_get.go b/resource-manager/apimanagement/2024-05-01/apipolicy/method_get.go new file mode 100644 index 00000000000..c62f27cb331 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apipolicy/method_get.go @@ -0,0 +1,83 @@ +package apipolicy + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyContract +} + +type GetOperationOptions struct { + Format *PolicyExportFormat +} + +func DefaultGetOperationOptions() GetOperationOptions { + return GetOperationOptions{} +} + +func (o GetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o GetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o GetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Format != nil { + out.Append("format", fmt.Sprintf("%v", *o.Format)) + } + return &out +} + +// Get ... +func (c ApiPolicyClient) Get(ctx context.Context, id ApiId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", 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 PolicyContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apipolicy/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/apipolicy/method_getentitytag.go new file mode 100644 index 00000000000..5ab255150b8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apipolicy/method_getentitytag.go @@ -0,0 +1,47 @@ +package apipolicy + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c ApiPolicyClient) GetEntityTag(ctx context.Context, id ApiId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: fmt.Sprintf("%s/policies/policy", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apipolicy/method_listbyapi.go b/resource-manager/apimanagement/2024-05-01/apipolicy/method_listbyapi.go new file mode 100644 index 00000000000..bbe7b58565b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apipolicy/method_listbyapi.go @@ -0,0 +1,105 @@ +package apipolicy + +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 ListByApiOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PolicyContract +} + +type ListByApiCompleteResult struct { + LatestHttpResponse *http.Response + Items []PolicyContract +} + +type ListByApiCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByApiCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByApi ... +func (c ApiPolicyClient) ListByApi(ctx context.Context, id ApiId) (result ListByApiOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByApiCustomPager{}, + Path: fmt.Sprintf("%s/policies", 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 *[]PolicyContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByApiComplete retrieves all the results into a single object +func (c ApiPolicyClient) ListByApiComplete(ctx context.Context, id ApiId) (ListByApiCompleteResult, error) { + return c.ListByApiCompleteMatchingPredicate(ctx, id, PolicyContractOperationPredicate{}) +} + +// ListByApiCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiPolicyClient) ListByApiCompleteMatchingPredicate(ctx context.Context, id ApiId, predicate PolicyContractOperationPredicate) (result ListByApiCompleteResult, err error) { + items := make([]PolicyContract, 0) + + resp, err := c.ListByApi(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByApiCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apipolicy/method_workspaceapipolicycreateorupdate.go b/resource-manager/apimanagement/2024-05-01/apipolicy/method_workspaceapipolicycreateorupdate.go new file mode 100644 index 00000000000..003cadb79ce --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apipolicy/method_workspaceapipolicycreateorupdate.go @@ -0,0 +1,88 @@ +package apipolicy + +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 WorkspaceApiPolicyCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyContract +} + +type WorkspaceApiPolicyCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceApiPolicyCreateOrUpdateOperationOptions() WorkspaceApiPolicyCreateOrUpdateOperationOptions { + return WorkspaceApiPolicyCreateOrUpdateOperationOptions{} +} + +func (o WorkspaceApiPolicyCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceApiPolicyCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiPolicyCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceApiPolicyCreateOrUpdate ... +func (c ApiPolicyClient) WorkspaceApiPolicyCreateOrUpdate(ctx context.Context, id WorkspaceApiId, input PolicyContract, options WorkspaceApiPolicyCreateOrUpdateOperationOptions) (result WorkspaceApiPolicyCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", 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 PolicyContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apipolicy/method_workspaceapipolicydelete.go b/resource-manager/apimanagement/2024-05-01/apipolicy/method_workspaceapipolicydelete.go new file mode 100644 index 00000000000..f2ceb3f9e4d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apipolicy/method_workspaceapipolicydelete.go @@ -0,0 +1,76 @@ +package apipolicy + +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 WorkspaceApiPolicyDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type WorkspaceApiPolicyDeleteOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceApiPolicyDeleteOperationOptions() WorkspaceApiPolicyDeleteOperationOptions { + return WorkspaceApiPolicyDeleteOperationOptions{} +} + +func (o WorkspaceApiPolicyDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceApiPolicyDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiPolicyDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceApiPolicyDelete ... +func (c ApiPolicyClient) WorkspaceApiPolicyDelete(ctx context.Context, id WorkspaceApiId, options WorkspaceApiPolicyDeleteOperationOptions) (result WorkspaceApiPolicyDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apipolicy/method_workspaceapipolicyget.go b/resource-manager/apimanagement/2024-05-01/apipolicy/method_workspaceapipolicyget.go new file mode 100644 index 00000000000..364bd7248f2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apipolicy/method_workspaceapipolicyget.go @@ -0,0 +1,83 @@ +package apipolicy + +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 WorkspaceApiPolicyGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyContract +} + +type WorkspaceApiPolicyGetOperationOptions struct { + Format *PolicyExportFormat +} + +func DefaultWorkspaceApiPolicyGetOperationOptions() WorkspaceApiPolicyGetOperationOptions { + return WorkspaceApiPolicyGetOperationOptions{} +} + +func (o WorkspaceApiPolicyGetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceApiPolicyGetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiPolicyGetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Format != nil { + out.Append("format", fmt.Sprintf("%v", *o.Format)) + } + return &out +} + +// WorkspaceApiPolicyGet ... +func (c ApiPolicyClient) WorkspaceApiPolicyGet(ctx context.Context, id WorkspaceApiId, options WorkspaceApiPolicyGetOperationOptions) (result WorkspaceApiPolicyGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", 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 PolicyContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apipolicy/method_workspaceapipolicygetentitytag.go b/resource-manager/apimanagement/2024-05-01/apipolicy/method_workspaceapipolicygetentitytag.go new file mode 100644 index 00000000000..47d8ff10508 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apipolicy/method_workspaceapipolicygetentitytag.go @@ -0,0 +1,47 @@ +package apipolicy + +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 WorkspaceApiPolicyGetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceApiPolicyGetEntityTag ... +func (c ApiPolicyClient) WorkspaceApiPolicyGetEntityTag(ctx context.Context, id WorkspaceApiId) (result WorkspaceApiPolicyGetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: fmt.Sprintf("%s/policies/policy", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apipolicy/method_workspaceapipolicylistbyapi.go b/resource-manager/apimanagement/2024-05-01/apipolicy/method_workspaceapipolicylistbyapi.go new file mode 100644 index 00000000000..39a1a6de1a1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apipolicy/method_workspaceapipolicylistbyapi.go @@ -0,0 +1,105 @@ +package apipolicy + +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 WorkspaceApiPolicyListByApiOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PolicyContract +} + +type WorkspaceApiPolicyListByApiCompleteResult struct { + LatestHttpResponse *http.Response + Items []PolicyContract +} + +type WorkspaceApiPolicyListByApiCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceApiPolicyListByApiCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceApiPolicyListByApi ... +func (c ApiPolicyClient) WorkspaceApiPolicyListByApi(ctx context.Context, id WorkspaceApiId) (result WorkspaceApiPolicyListByApiOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &WorkspaceApiPolicyListByApiCustomPager{}, + Path: fmt.Sprintf("%s/policies", 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 *[]PolicyContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceApiPolicyListByApiComplete retrieves all the results into a single object +func (c ApiPolicyClient) WorkspaceApiPolicyListByApiComplete(ctx context.Context, id WorkspaceApiId) (WorkspaceApiPolicyListByApiCompleteResult, error) { + return c.WorkspaceApiPolicyListByApiCompleteMatchingPredicate(ctx, id, PolicyContractOperationPredicate{}) +} + +// WorkspaceApiPolicyListByApiCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiPolicyClient) WorkspaceApiPolicyListByApiCompleteMatchingPredicate(ctx context.Context, id WorkspaceApiId, predicate PolicyContractOperationPredicate) (result WorkspaceApiPolicyListByApiCompleteResult, err error) { + items := make([]PolicyContract, 0) + + resp, err := c.WorkspaceApiPolicyListByApi(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceApiPolicyListByApiCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apipolicy/model_policycontract.go b/resource-manager/apimanagement/2024-05-01/apipolicy/model_policycontract.go new file mode 100644 index 00000000000..e44856ff27f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apipolicy/model_policycontract.go @@ -0,0 +1,11 @@ +package apipolicy + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PolicyContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apipolicy/model_policycontractproperties.go b/resource-manager/apimanagement/2024-05-01/apipolicy/model_policycontractproperties.go new file mode 100644 index 00000000000..3ffd1c627e8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apipolicy/model_policycontractproperties.go @@ -0,0 +1,9 @@ +package apipolicy + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyContractProperties struct { + Format *PolicyContentFormat `json:"format,omitempty"` + Value string `json:"value"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apipolicy/predicates.go b/resource-manager/apimanagement/2024-05-01/apipolicy/predicates.go new file mode 100644 index 00000000000..63bbd7be660 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apipolicy/predicates.go @@ -0,0 +1,27 @@ +package apipolicy + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PolicyContractOperationPredicate) Matches(input PolicyContract) 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/apimanagement/2024-05-01/apipolicy/version.go b/resource-manager/apimanagement/2024-05-01/apipolicy/version.go new file mode 100644 index 00000000000..a1fd3c3c145 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apipolicy/version.go @@ -0,0 +1,12 @@ +package apipolicy + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apipolicy/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apiproduct/README.md b/resource-manager/apimanagement/2024-05-01/apiproduct/README.md new file mode 100644 index 00000000000..de0f38fc6a2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiproduct/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apiproduct` Documentation + +The `apiproduct` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apiproduct" +``` + + +### Client Initialization + +```go +client := apiproduct.NewApiProductClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiProductClient.ListByApis` + +```go +ctx := context.TODO() +id := apiproduct.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +// alternatively `client.ListByApis(ctx, id, apiproduct.DefaultListByApisOperationOptions())` can be used to do batched pagination +items, err := client.ListByApisComplete(ctx, id, apiproduct.DefaultListByApisOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/apiproduct/client.go b/resource-manager/apimanagement/2024-05-01/apiproduct/client.go new file mode 100644 index 00000000000..e7774a6266c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiproduct/client.go @@ -0,0 +1,26 @@ +package apiproduct + +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 ApiProductClient struct { + Client *resourcemanager.Client +} + +func NewApiProductClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiProductClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apiproduct", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiProductClient: %+v", err) + } + + return &ApiProductClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apiproduct/constants.go b/resource-manager/apimanagement/2024-05-01/apiproduct/constants.go new file mode 100644 index 00000000000..12fdc8dd3d6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiproduct/constants.go @@ -0,0 +1,51 @@ +package apiproduct + +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 ProductState string + +const ( + ProductStateNotPublished ProductState = "notPublished" + ProductStatePublished ProductState = "published" +) + +func PossibleValuesForProductState() []string { + return []string{ + string(ProductStateNotPublished), + string(ProductStatePublished), + } +} + +func (s *ProductState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProductState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProductState(input string) (*ProductState, error) { + vals := map[string]ProductState{ + "notpublished": ProductStateNotPublished, + "published": ProductStatePublished, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProductState(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apiproduct/id_api.go b/resource-manager/apimanagement/2024-05-01/apiproduct/id_api.go new file mode 100644 index 00000000000..b14e77a5f55 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiproduct/id_api.go @@ -0,0 +1,139 @@ +package apiproduct + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiId{}) +} + +var _ resourceids.ResourceId = &ApiId{} + +// ApiId is a struct representing the Resource ID for a Api +type ApiId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string +} + +// NewApiID returns a new ApiId struct +func NewApiID(subscriptionId string, resourceGroupName string, serviceName string, apiId string) ApiId { + return ApiId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + } +} + +// ParseApiID parses 'input' into a ApiId +func ParseApiID(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiIDInsensitively parses 'input' case-insensitively into a ApiId +// note: this method should only be used for API response data and not user input +func ParseApiIDInsensitively(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + return nil +} + +// ValidateApiID checks that 'input' can be parsed as a Api ID +func ValidateApiID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api ID +func (id ApiId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api ID +func (id ApiId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + } +} + +// String returns a human-readable description of this Api ID +func (id ApiId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + } + return fmt.Sprintf("Api (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apiproduct/id_api_test.go b/resource-manager/apimanagement/2024-05-01/apiproduct/id_api_test.go new file mode 100644 index 00000000000..1a42ab54438 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiproduct/id_api_test.go @@ -0,0 +1,327 @@ +package apiproduct + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiId{} + +func TestNewApiID(t *testing.T) { + id := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } +} + +func TestFormatApiID(t *testing.T) { + actual := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestParseApiIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestSegmentsForApiId(t *testing.T) { + segments := ApiId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apiproduct/method_listbyapis.go b/resource-manager/apimanagement/2024-05-01/apiproduct/method_listbyapis.go new file mode 100644 index 00000000000..9a4501fc786 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiproduct/method_listbyapis.go @@ -0,0 +1,141 @@ +package apiproduct + +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 ListByApisOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ProductContract +} + +type ListByApisCompleteResult struct { + LatestHttpResponse *http.Response + Items []ProductContract +} + +type ListByApisOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByApisOperationOptions() ListByApisOperationOptions { + return ListByApisOperationOptions{} +} + +func (o ListByApisOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByApisOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByApisOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByApisCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByApisCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByApis ... +func (c ApiProductClient) ListByApis(ctx context.Context, id ApiId, options ListByApisOperationOptions) (result ListByApisOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByApisCustomPager{}, + Path: fmt.Sprintf("%s/products", 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 *[]ProductContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByApisComplete retrieves all the results into a single object +func (c ApiProductClient) ListByApisComplete(ctx context.Context, id ApiId, options ListByApisOperationOptions) (ListByApisCompleteResult, error) { + return c.ListByApisCompleteMatchingPredicate(ctx, id, options, ProductContractOperationPredicate{}) +} + +// ListByApisCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiProductClient) ListByApisCompleteMatchingPredicate(ctx context.Context, id ApiId, options ListByApisOperationOptions, predicate ProductContractOperationPredicate) (result ListByApisCompleteResult, err error) { + items := make([]ProductContract, 0) + + resp, err := c.ListByApis(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByApisCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiproduct/model_productcontract.go b/resource-manager/apimanagement/2024-05-01/apiproduct/model_productcontract.go new file mode 100644 index 00000000000..79b328d0c75 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiproduct/model_productcontract.go @@ -0,0 +1,11 @@ +package apiproduct + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ProductContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apiproduct/model_productcontractproperties.go b/resource-manager/apimanagement/2024-05-01/apiproduct/model_productcontractproperties.go new file mode 100644 index 00000000000..72d6218fe05 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiproduct/model_productcontractproperties.go @@ -0,0 +1,14 @@ +package apiproduct + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductContractProperties struct { + ApprovalRequired *bool `json:"approvalRequired,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName string `json:"displayName"` + State *ProductState `json:"state,omitempty"` + SubscriptionRequired *bool `json:"subscriptionRequired,omitempty"` + SubscriptionsLimit *int64 `json:"subscriptionsLimit,omitempty"` + Terms *string `json:"terms,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apiproduct/predicates.go b/resource-manager/apimanagement/2024-05-01/apiproduct/predicates.go new file mode 100644 index 00000000000..8d4210b9d4c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiproduct/predicates.go @@ -0,0 +1,27 @@ +package apiproduct + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ProductContractOperationPredicate) Matches(input ProductContract) 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/apimanagement/2024-05-01/apiproduct/version.go b/resource-manager/apimanagement/2024-05-01/apiproduct/version.go new file mode 100644 index 00000000000..daaf7de5d3e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiproduct/version.go @@ -0,0 +1,12 @@ +package apiproduct + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apiproduct/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/README.md b/resource-manager/apimanagement/2024-05-01/apirelease/README.md new file mode 100644 index 00000000000..2f015541dea --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/README.md @@ -0,0 +1,234 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apirelease` Documentation + +The `apirelease` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apirelease" +``` + + +### Client Initialization + +```go +client := apirelease.NewApiReleaseClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiReleaseClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := apirelease.NewReleaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "releaseIdValue") + +payload := apirelease.ApiReleaseContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, apirelease.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiReleaseClient.Delete` + +```go +ctx := context.TODO() +id := apirelease.NewReleaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "releaseIdValue") + +read, err := client.Delete(ctx, id, apirelease.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiReleaseClient.Get` + +```go +ctx := context.TODO() +id := apirelease.NewReleaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "releaseIdValue") + +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: `ApiReleaseClient.GetEntityTag` + +```go +ctx := context.TODO() +id := apirelease.NewReleaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "releaseIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiReleaseClient.ListByService` + +```go +ctx := context.TODO() +id := apirelease.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +// alternatively `client.ListByService(ctx, id, apirelease.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, apirelease.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ApiReleaseClient.Update` + +```go +ctx := context.TODO() +id := apirelease.NewReleaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "releaseIdValue") + +payload := apirelease.ApiReleaseContract{ + // ... +} + + +read, err := client.Update(ctx, id, payload, apirelease.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiReleaseClient.WorkspaceApiReleaseCreateOrUpdate` + +```go +ctx := context.TODO() +id := apirelease.NewApiReleaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "releaseIdValue") + +payload := apirelease.ApiReleaseContract{ + // ... +} + + +read, err := client.WorkspaceApiReleaseCreateOrUpdate(ctx, id, payload, apirelease.DefaultWorkspaceApiReleaseCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiReleaseClient.WorkspaceApiReleaseDelete` + +```go +ctx := context.TODO() +id := apirelease.NewApiReleaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "releaseIdValue") + +read, err := client.WorkspaceApiReleaseDelete(ctx, id, apirelease.DefaultWorkspaceApiReleaseDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiReleaseClient.WorkspaceApiReleaseGet` + +```go +ctx := context.TODO() +id := apirelease.NewApiReleaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "releaseIdValue") + +read, err := client.WorkspaceApiReleaseGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiReleaseClient.WorkspaceApiReleaseGetEntityTag` + +```go +ctx := context.TODO() +id := apirelease.NewApiReleaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "releaseIdValue") + +read, err := client.WorkspaceApiReleaseGetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiReleaseClient.WorkspaceApiReleaseListByService` + +```go +ctx := context.TODO() +id := apirelease.NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue") + +// alternatively `client.WorkspaceApiReleaseListByService(ctx, id, apirelease.DefaultWorkspaceApiReleaseListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.WorkspaceApiReleaseListByServiceComplete(ctx, id, apirelease.DefaultWorkspaceApiReleaseListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ApiReleaseClient.WorkspaceApiReleaseUpdate` + +```go +ctx := context.TODO() +id := apirelease.NewApiReleaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "releaseIdValue") + +payload := apirelease.ApiReleaseContract{ + // ... +} + + +read, err := client.WorkspaceApiReleaseUpdate(ctx, id, payload, apirelease.DefaultWorkspaceApiReleaseUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/client.go b/resource-manager/apimanagement/2024-05-01/apirelease/client.go new file mode 100644 index 00000000000..5ce0c50057f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/client.go @@ -0,0 +1,26 @@ +package apirelease + +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 ApiReleaseClient struct { + Client *resourcemanager.Client +} + +func NewApiReleaseClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiReleaseClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apirelease", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiReleaseClient: %+v", err) + } + + return &ApiReleaseClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/id_api.go b/resource-manager/apimanagement/2024-05-01/apirelease/id_api.go new file mode 100644 index 00000000000..8cb60bea6b5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/id_api.go @@ -0,0 +1,139 @@ +package apirelease + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiId{}) +} + +var _ resourceids.ResourceId = &ApiId{} + +// ApiId is a struct representing the Resource ID for a Api +type ApiId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string +} + +// NewApiID returns a new ApiId struct +func NewApiID(subscriptionId string, resourceGroupName string, serviceName string, apiId string) ApiId { + return ApiId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + } +} + +// ParseApiID parses 'input' into a ApiId +func ParseApiID(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiIDInsensitively parses 'input' case-insensitively into a ApiId +// note: this method should only be used for API response data and not user input +func ParseApiIDInsensitively(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + return nil +} + +// ValidateApiID checks that 'input' can be parsed as a Api ID +func ValidateApiID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api ID +func (id ApiId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api ID +func (id ApiId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + } +} + +// String returns a human-readable description of this Api ID +func (id ApiId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + } + return fmt.Sprintf("Api (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/id_api_test.go b/resource-manager/apimanagement/2024-05-01/apirelease/id_api_test.go new file mode 100644 index 00000000000..b604cd7f02e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/id_api_test.go @@ -0,0 +1,327 @@ +package apirelease + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiId{} + +func TestNewApiID(t *testing.T) { + id := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } +} + +func TestFormatApiID(t *testing.T) { + actual := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestParseApiIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestSegmentsForApiId(t *testing.T) { + segments := ApiId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/id_apirelease.go b/resource-manager/apimanagement/2024-05-01/apirelease/id_apirelease.go new file mode 100644 index 00000000000..e93d37f020b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/id_apirelease.go @@ -0,0 +1,157 @@ +package apirelease + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiReleaseId{}) +} + +var _ resourceids.ResourceId = &ApiReleaseId{} + +// ApiReleaseId is a struct representing the Resource ID for a Api Release +type ApiReleaseId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + ApiId string + ReleaseId string +} + +// NewApiReleaseID returns a new ApiReleaseId struct +func NewApiReleaseID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, apiId string, releaseId string) ApiReleaseId { + return ApiReleaseId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + ApiId: apiId, + ReleaseId: releaseId, + } +} + +// ParseApiReleaseID parses 'input' into a ApiReleaseId +func ParseApiReleaseID(input string) (*ApiReleaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiReleaseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiReleaseId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiReleaseIDInsensitively parses 'input' case-insensitively into a ApiReleaseId +// note: this method should only be used for API response data and not user input +func ParseApiReleaseIDInsensitively(input string) (*ApiReleaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiReleaseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiReleaseId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiReleaseId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + if id.ReleaseId, ok = input.Parsed["releaseId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "releaseId", input) + } + + return nil +} + +// ValidateApiReleaseID checks that 'input' can be parsed as a Api Release ID +func ValidateApiReleaseID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiReleaseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api Release ID +func (id ApiReleaseId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/apis/%s/releases/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.ApiId, id.ReleaseId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api Release ID +func (id ApiReleaseId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + resourceids.StaticSegment("staticReleases", "releases", "releases"), + resourceids.UserSpecifiedSegment("releaseId", "releaseIdValue"), + } +} + +// String returns a human-readable description of this Api Release ID +func (id ApiReleaseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Api: %q", id.ApiId), + fmt.Sprintf("Release: %q", id.ReleaseId), + } + return fmt.Sprintf("Api Release (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/id_apirelease_test.go b/resource-manager/apimanagement/2024-05-01/apirelease/id_apirelease_test.go new file mode 100644 index 00000000000..4ba207094a5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/id_apirelease_test.go @@ -0,0 +1,417 @@ +package apirelease + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiReleaseId{} + +func TestNewApiReleaseID(t *testing.T) { + id := NewApiReleaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "releaseIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } + + if id.ReleaseId != "releaseIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReleaseId'", id.ReleaseId, "releaseIdValue") + } +} + +func TestFormatApiReleaseID(t *testing.T) { + actual := NewApiReleaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "releaseIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/releases/releaseIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiReleaseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiReleaseId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/releases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/releases/releaseIdValue", + Expected: &ApiReleaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ApiId: "apiIdValue", + ReleaseId: "releaseIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/releases/releaseIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiReleaseID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.ReleaseId != v.Expected.ReleaseId { + t.Fatalf("Expected %q but got %q for ReleaseId", v.Expected.ReleaseId, actual.ReleaseId) + } + + } +} + +func TestParseApiReleaseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiReleaseId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/releases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE/rElEaSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/releases/releaseIdValue", + Expected: &ApiReleaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ApiId: "apiIdValue", + ReleaseId: "releaseIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/releases/releaseIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE/rElEaSeS/rElEaSeIdVaLuE", + Expected: &ApiReleaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + ApiId: "aPiIdVaLuE", + ReleaseId: "rElEaSeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE/rElEaSeS/rElEaSeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiReleaseIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.ReleaseId != v.Expected.ReleaseId { + t.Fatalf("Expected %q but got %q for ReleaseId", v.Expected.ReleaseId, actual.ReleaseId) + } + + } +} + +func TestSegmentsForApiReleaseId(t *testing.T) { + segments := ApiReleaseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiReleaseId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/id_release.go b/resource-manager/apimanagement/2024-05-01/apirelease/id_release.go new file mode 100644 index 00000000000..782521151d8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/id_release.go @@ -0,0 +1,148 @@ +package apirelease + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ReleaseId{}) +} + +var _ resourceids.ResourceId = &ReleaseId{} + +// ReleaseId is a struct representing the Resource ID for a Release +type ReleaseId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string + ReleaseId string +} + +// NewReleaseID returns a new ReleaseId struct +func NewReleaseID(subscriptionId string, resourceGroupName string, serviceName string, apiId string, releaseId string) ReleaseId { + return ReleaseId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + ReleaseId: releaseId, + } +} + +// ParseReleaseID parses 'input' into a ReleaseId +func ParseReleaseID(input string) (*ReleaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&ReleaseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ReleaseId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseReleaseIDInsensitively parses 'input' case-insensitively into a ReleaseId +// note: this method should only be used for API response data and not user input +func ParseReleaseIDInsensitively(input string) (*ReleaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&ReleaseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ReleaseId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ReleaseId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + if id.ReleaseId, ok = input.Parsed["releaseId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "releaseId", input) + } + + return nil +} + +// ValidateReleaseID checks that 'input' can be parsed as a Release ID +func ValidateReleaseID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseReleaseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Release ID +func (id ReleaseId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s/releases/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId, id.ReleaseId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Release ID +func (id ReleaseId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + resourceids.StaticSegment("staticReleases", "releases", "releases"), + resourceids.UserSpecifiedSegment("releaseId", "releaseIdValue"), + } +} + +// String returns a human-readable description of this Release ID +func (id ReleaseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + fmt.Sprintf("Release: %q", id.ReleaseId), + } + return fmt.Sprintf("Release (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/id_release_test.go b/resource-manager/apimanagement/2024-05-01/apirelease/id_release_test.go new file mode 100644 index 00000000000..925135cd424 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/id_release_test.go @@ -0,0 +1,372 @@ +package apirelease + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ReleaseId{} + +func TestNewReleaseID(t *testing.T) { + id := NewReleaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "releaseIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } + + if id.ReleaseId != "releaseIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ReleaseId'", id.ReleaseId, "releaseIdValue") + } +} + +func TestFormatReleaseID(t *testing.T) { + actual := NewReleaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "releaseIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/releases/releaseIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReleaseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReleaseId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/releases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/releases/releaseIdValue", + Expected: &ReleaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + ReleaseId: "releaseIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/releases/releaseIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReleaseID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.ReleaseId != v.Expected.ReleaseId { + t.Fatalf("Expected %q but got %q for ReleaseId", v.Expected.ReleaseId, actual.ReleaseId) + } + + } +} + +func TestParseReleaseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReleaseId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/releases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/rElEaSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/releases/releaseIdValue", + Expected: &ReleaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + ReleaseId: "releaseIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/releases/releaseIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/rElEaSeS/rElEaSeIdVaLuE", + Expected: &ReleaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + ReleaseId: "rElEaSeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/rElEaSeS/rElEaSeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReleaseIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.ReleaseId != v.Expected.ReleaseId { + t.Fatalf("Expected %q but got %q for ReleaseId", v.Expected.ReleaseId, actual.ReleaseId) + } + + } +} + +func TestSegmentsForReleaseId(t *testing.T) { + segments := ReleaseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReleaseId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/id_workspaceapi.go b/resource-manager/apimanagement/2024-05-01/apirelease/id_workspaceapi.go new file mode 100644 index 00000000000..708a5e83416 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/id_workspaceapi.go @@ -0,0 +1,148 @@ +package apirelease + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceApiId{}) +} + +var _ resourceids.ResourceId = &WorkspaceApiId{} + +// WorkspaceApiId is a struct representing the Resource ID for a Workspace Api +type WorkspaceApiId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + ApiId string +} + +// NewWorkspaceApiID returns a new WorkspaceApiId struct +func NewWorkspaceApiID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, apiId string) WorkspaceApiId { + return WorkspaceApiId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + ApiId: apiId, + } +} + +// ParseWorkspaceApiID parses 'input' into a WorkspaceApiId +func ParseWorkspaceApiID(input string) (*WorkspaceApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceApiId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceApiIDInsensitively parses 'input' case-insensitively into a WorkspaceApiId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceApiIDInsensitively(input string) (*WorkspaceApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceApiId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceApiId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + return nil +} + +// ValidateWorkspaceApiID checks that 'input' can be parsed as a Workspace Api ID +func ValidateWorkspaceApiID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceApiID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Api ID +func (id WorkspaceApiId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/apis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.ApiId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Api ID +func (id WorkspaceApiId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + } +} + +// String returns a human-readable description of this Workspace Api ID +func (id WorkspaceApiId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Api: %q", id.ApiId), + } + return fmt.Sprintf("Workspace Api (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/id_workspaceapi_test.go b/resource-manager/apimanagement/2024-05-01/apirelease/id_workspaceapi_test.go new file mode 100644 index 00000000000..1083a19b1f6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/id_workspaceapi_test.go @@ -0,0 +1,372 @@ +package apirelease + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceApiId{} + +func TestNewWorkspaceApiID(t *testing.T) { + id := NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } +} + +func TestFormatWorkspaceApiID(t *testing.T) { + actual := NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceApiID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue", + Expected: &WorkspaceApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceApiID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestParseWorkspaceApiIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue", + Expected: &WorkspaceApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE", + Expected: &WorkspaceApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + ApiId: "aPiIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceApiIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestSegmentsForWorkspaceApiId(t *testing.T) { + segments := WorkspaceApiId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceApiId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/apirelease/method_createorupdate.go new file mode 100644 index 00000000000..2b23b8d16a6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/method_createorupdate.go @@ -0,0 +1,88 @@ +package apirelease + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ApiReleaseContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c ApiReleaseClient) CreateOrUpdate(ctx context.Context, id ReleaseId, input ApiReleaseContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 ApiReleaseContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/method_delete.go b/resource-manager/apimanagement/2024-05-01/apirelease/method_delete.go new file mode 100644 index 00000000000..d7f28534465 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/method_delete.go @@ -0,0 +1,76 @@ +package apirelease + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c ApiReleaseClient) Delete(ctx context.Context, id ReleaseId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/method_get.go b/resource-manager/apimanagement/2024-05-01/apirelease/method_get.go new file mode 100644 index 00000000000..4f45a0505aa --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/method_get.go @@ -0,0 +1,54 @@ +package apirelease + +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 *ApiReleaseContract +} + +// Get ... +func (c ApiReleaseClient) Get(ctx context.Context, id ReleaseId) (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 ApiReleaseContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/apirelease/method_getentitytag.go new file mode 100644 index 00000000000..97a2ff54ef1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/method_getentitytag.go @@ -0,0 +1,46 @@ +package apirelease + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c ApiReleaseClient) GetEntityTag(ctx context.Context, id ReleaseId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/apirelease/method_listbyservice.go new file mode 100644 index 00000000000..509f7241d4f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/method_listbyservice.go @@ -0,0 +1,141 @@ +package apirelease + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ApiReleaseContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ApiReleaseContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c ApiReleaseClient) ListByService(ctx context.Context, id ApiId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/releases", 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 *[]ApiReleaseContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c ApiReleaseClient) ListByServiceComplete(ctx context.Context, id ApiId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, ApiReleaseContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiReleaseClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ApiId, options ListByServiceOperationOptions, predicate ApiReleaseContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]ApiReleaseContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/method_update.go b/resource-manager/apimanagement/2024-05-01/apirelease/method_update.go new file mode 100644 index 00000000000..1e51ca66c45 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/method_update.go @@ -0,0 +1,87 @@ +package apirelease + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ApiReleaseContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c ApiReleaseClient) Update(ctx context.Context, id ReleaseId, input ApiReleaseContract, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 ApiReleaseContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/method_workspaceapireleasecreateorupdate.go b/resource-manager/apimanagement/2024-05-01/apirelease/method_workspaceapireleasecreateorupdate.go new file mode 100644 index 00000000000..3dcd9fce3ab --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/method_workspaceapireleasecreateorupdate.go @@ -0,0 +1,88 @@ +package apirelease + +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 WorkspaceApiReleaseCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ApiReleaseContract +} + +type WorkspaceApiReleaseCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceApiReleaseCreateOrUpdateOperationOptions() WorkspaceApiReleaseCreateOrUpdateOperationOptions { + return WorkspaceApiReleaseCreateOrUpdateOperationOptions{} +} + +func (o WorkspaceApiReleaseCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceApiReleaseCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiReleaseCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceApiReleaseCreateOrUpdate ... +func (c ApiReleaseClient) WorkspaceApiReleaseCreateOrUpdate(ctx context.Context, id ApiReleaseId, input ApiReleaseContract, options WorkspaceApiReleaseCreateOrUpdateOperationOptions) (result WorkspaceApiReleaseCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 ApiReleaseContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/method_workspaceapireleasedelete.go b/resource-manager/apimanagement/2024-05-01/apirelease/method_workspaceapireleasedelete.go new file mode 100644 index 00000000000..0fd63c74e77 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/method_workspaceapireleasedelete.go @@ -0,0 +1,76 @@ +package apirelease + +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 WorkspaceApiReleaseDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type WorkspaceApiReleaseDeleteOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceApiReleaseDeleteOperationOptions() WorkspaceApiReleaseDeleteOperationOptions { + return WorkspaceApiReleaseDeleteOperationOptions{} +} + +func (o WorkspaceApiReleaseDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceApiReleaseDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiReleaseDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceApiReleaseDelete ... +func (c ApiReleaseClient) WorkspaceApiReleaseDelete(ctx context.Context, id ApiReleaseId, options WorkspaceApiReleaseDeleteOperationOptions) (result WorkspaceApiReleaseDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/method_workspaceapireleaseget.go b/resource-manager/apimanagement/2024-05-01/apirelease/method_workspaceapireleaseget.go new file mode 100644 index 00000000000..df9e7f1c4c0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/method_workspaceapireleaseget.go @@ -0,0 +1,54 @@ +package apirelease + +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 WorkspaceApiReleaseGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ApiReleaseContract +} + +// WorkspaceApiReleaseGet ... +func (c ApiReleaseClient) WorkspaceApiReleaseGet(ctx context.Context, id ApiReleaseId) (result WorkspaceApiReleaseGetOperationResponse, 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 ApiReleaseContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/method_workspaceapireleasegetentitytag.go b/resource-manager/apimanagement/2024-05-01/apirelease/method_workspaceapireleasegetentitytag.go new file mode 100644 index 00000000000..561270d9fa8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/method_workspaceapireleasegetentitytag.go @@ -0,0 +1,46 @@ +package apirelease + +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 WorkspaceApiReleaseGetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceApiReleaseGetEntityTag ... +func (c ApiReleaseClient) WorkspaceApiReleaseGetEntityTag(ctx context.Context, id ApiReleaseId) (result WorkspaceApiReleaseGetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/method_workspaceapireleaselistbyservice.go b/resource-manager/apimanagement/2024-05-01/apirelease/method_workspaceapireleaselistbyservice.go new file mode 100644 index 00000000000..578ad231c48 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/method_workspaceapireleaselistbyservice.go @@ -0,0 +1,141 @@ +package apirelease + +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 WorkspaceApiReleaseListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ApiReleaseContract +} + +type WorkspaceApiReleaseListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ApiReleaseContract +} + +type WorkspaceApiReleaseListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultWorkspaceApiReleaseListByServiceOperationOptions() WorkspaceApiReleaseListByServiceOperationOptions { + return WorkspaceApiReleaseListByServiceOperationOptions{} +} + +func (o WorkspaceApiReleaseListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceApiReleaseListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiReleaseListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspaceApiReleaseListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceApiReleaseListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceApiReleaseListByService ... +func (c ApiReleaseClient) WorkspaceApiReleaseListByService(ctx context.Context, id WorkspaceApiId, options WorkspaceApiReleaseListByServiceOperationOptions) (result WorkspaceApiReleaseListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspaceApiReleaseListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/releases", 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 *[]ApiReleaseContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceApiReleaseListByServiceComplete retrieves all the results into a single object +func (c ApiReleaseClient) WorkspaceApiReleaseListByServiceComplete(ctx context.Context, id WorkspaceApiId, options WorkspaceApiReleaseListByServiceOperationOptions) (WorkspaceApiReleaseListByServiceCompleteResult, error) { + return c.WorkspaceApiReleaseListByServiceCompleteMatchingPredicate(ctx, id, options, ApiReleaseContractOperationPredicate{}) +} + +// WorkspaceApiReleaseListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiReleaseClient) WorkspaceApiReleaseListByServiceCompleteMatchingPredicate(ctx context.Context, id WorkspaceApiId, options WorkspaceApiReleaseListByServiceOperationOptions, predicate ApiReleaseContractOperationPredicate) (result WorkspaceApiReleaseListByServiceCompleteResult, err error) { + items := make([]ApiReleaseContract, 0) + + resp, err := c.WorkspaceApiReleaseListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceApiReleaseListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/method_workspaceapireleaseupdate.go b/resource-manager/apimanagement/2024-05-01/apirelease/method_workspaceapireleaseupdate.go new file mode 100644 index 00000000000..d301c6d2adc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/method_workspaceapireleaseupdate.go @@ -0,0 +1,87 @@ +package apirelease + +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 WorkspaceApiReleaseUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ApiReleaseContract +} + +type WorkspaceApiReleaseUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceApiReleaseUpdateOperationOptions() WorkspaceApiReleaseUpdateOperationOptions { + return WorkspaceApiReleaseUpdateOperationOptions{} +} + +func (o WorkspaceApiReleaseUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceApiReleaseUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiReleaseUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceApiReleaseUpdate ... +func (c ApiReleaseClient) WorkspaceApiReleaseUpdate(ctx context.Context, id ApiReleaseId, input ApiReleaseContract, options WorkspaceApiReleaseUpdateOperationOptions) (result WorkspaceApiReleaseUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 ApiReleaseContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/model_apireleasecontract.go b/resource-manager/apimanagement/2024-05-01/apirelease/model_apireleasecontract.go new file mode 100644 index 00000000000..fae993ebed5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/model_apireleasecontract.go @@ -0,0 +1,11 @@ +package apirelease + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiReleaseContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ApiReleaseContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/model_apireleasecontractproperties.go b/resource-manager/apimanagement/2024-05-01/apirelease/model_apireleasecontractproperties.go new file mode 100644 index 00000000000..56b6fec96ca --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/model_apireleasecontractproperties.go @@ -0,0 +1,41 @@ +package apirelease + +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 ApiReleaseContractProperties struct { + ApiId *string `json:"apiId,omitempty"` + CreatedDateTime *string `json:"createdDateTime,omitempty"` + Notes *string `json:"notes,omitempty"` + UpdatedDateTime *string `json:"updatedDateTime,omitempty"` +} + +func (o *ApiReleaseContractProperties) GetCreatedDateTimeAsTime() (*time.Time, error) { + if o.CreatedDateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedDateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ApiReleaseContractProperties) SetCreatedDateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedDateTime = &formatted +} + +func (o *ApiReleaseContractProperties) GetUpdatedDateTimeAsTime() (*time.Time, error) { + if o.UpdatedDateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.UpdatedDateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ApiReleaseContractProperties) SetUpdatedDateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.UpdatedDateTime = &formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/apirelease/predicates.go b/resource-manager/apimanagement/2024-05-01/apirelease/predicates.go new file mode 100644 index 00000000000..97527612637 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/predicates.go @@ -0,0 +1,27 @@ +package apirelease + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiReleaseContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ApiReleaseContractOperationPredicate) Matches(input ApiReleaseContract) 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/apimanagement/2024-05-01/apirelease/version.go b/resource-manager/apimanagement/2024-05-01/apirelease/version.go new file mode 100644 index 00000000000..2e0e2d68707 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirelease/version.go @@ -0,0 +1,12 @@ +package apirelease + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apirelease/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apirevision/README.md b/resource-manager/apimanagement/2024-05-01/apirevision/README.md new file mode 100644 index 00000000000..35af698cb3b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirevision/README.md @@ -0,0 +1,54 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apirevision` Documentation + +The `apirevision` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apirevision" +``` + + +### Client Initialization + +```go +client := apirevision.NewApiRevisionClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiRevisionClient.ListByService` + +```go +ctx := context.TODO() +id := apirevision.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +// alternatively `client.ListByService(ctx, id, apirevision.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, apirevision.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ApiRevisionClient.WorkspaceApiRevisionListByService` + +```go +ctx := context.TODO() +id := apirevision.NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue") + +// alternatively `client.WorkspaceApiRevisionListByService(ctx, id, apirevision.DefaultWorkspaceApiRevisionListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.WorkspaceApiRevisionListByServiceComplete(ctx, id, apirevision.DefaultWorkspaceApiRevisionListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/apirevision/client.go b/resource-manager/apimanagement/2024-05-01/apirevision/client.go new file mode 100644 index 00000000000..d44402ed6ae --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirevision/client.go @@ -0,0 +1,26 @@ +package apirevision + +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 ApiRevisionClient struct { + Client *resourcemanager.Client +} + +func NewApiRevisionClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiRevisionClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apirevision", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiRevisionClient: %+v", err) + } + + return &ApiRevisionClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apirevision/id_api.go b/resource-manager/apimanagement/2024-05-01/apirevision/id_api.go new file mode 100644 index 00000000000..b7fe8776e72 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirevision/id_api.go @@ -0,0 +1,139 @@ +package apirevision + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiId{}) +} + +var _ resourceids.ResourceId = &ApiId{} + +// ApiId is a struct representing the Resource ID for a Api +type ApiId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string +} + +// NewApiID returns a new ApiId struct +func NewApiID(subscriptionId string, resourceGroupName string, serviceName string, apiId string) ApiId { + return ApiId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + } +} + +// ParseApiID parses 'input' into a ApiId +func ParseApiID(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiIDInsensitively parses 'input' case-insensitively into a ApiId +// note: this method should only be used for API response data and not user input +func ParseApiIDInsensitively(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + return nil +} + +// ValidateApiID checks that 'input' can be parsed as a Api ID +func ValidateApiID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api ID +func (id ApiId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api ID +func (id ApiId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + } +} + +// String returns a human-readable description of this Api ID +func (id ApiId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + } + return fmt.Sprintf("Api (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apirevision/id_api_test.go b/resource-manager/apimanagement/2024-05-01/apirevision/id_api_test.go new file mode 100644 index 00000000000..9738159ed89 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirevision/id_api_test.go @@ -0,0 +1,327 @@ +package apirevision + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiId{} + +func TestNewApiID(t *testing.T) { + id := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } +} + +func TestFormatApiID(t *testing.T) { + actual := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestParseApiIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestSegmentsForApiId(t *testing.T) { + segments := ApiId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apirevision/id_workspaceapi.go b/resource-manager/apimanagement/2024-05-01/apirevision/id_workspaceapi.go new file mode 100644 index 00000000000..ca64dd7d7de --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirevision/id_workspaceapi.go @@ -0,0 +1,148 @@ +package apirevision + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceApiId{}) +} + +var _ resourceids.ResourceId = &WorkspaceApiId{} + +// WorkspaceApiId is a struct representing the Resource ID for a Workspace Api +type WorkspaceApiId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + ApiId string +} + +// NewWorkspaceApiID returns a new WorkspaceApiId struct +func NewWorkspaceApiID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, apiId string) WorkspaceApiId { + return WorkspaceApiId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + ApiId: apiId, + } +} + +// ParseWorkspaceApiID parses 'input' into a WorkspaceApiId +func ParseWorkspaceApiID(input string) (*WorkspaceApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceApiId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceApiIDInsensitively parses 'input' case-insensitively into a WorkspaceApiId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceApiIDInsensitively(input string) (*WorkspaceApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceApiId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceApiId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + return nil +} + +// ValidateWorkspaceApiID checks that 'input' can be parsed as a Workspace Api ID +func ValidateWorkspaceApiID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceApiID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Api ID +func (id WorkspaceApiId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/apis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.ApiId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Api ID +func (id WorkspaceApiId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + } +} + +// String returns a human-readable description of this Workspace Api ID +func (id WorkspaceApiId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Api: %q", id.ApiId), + } + return fmt.Sprintf("Workspace Api (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apirevision/id_workspaceapi_test.go b/resource-manager/apimanagement/2024-05-01/apirevision/id_workspaceapi_test.go new file mode 100644 index 00000000000..c283b9d8a1f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirevision/id_workspaceapi_test.go @@ -0,0 +1,372 @@ +package apirevision + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceApiId{} + +func TestNewWorkspaceApiID(t *testing.T) { + id := NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } +} + +func TestFormatWorkspaceApiID(t *testing.T) { + actual := NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceApiID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue", + Expected: &WorkspaceApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceApiID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestParseWorkspaceApiIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue", + Expected: &WorkspaceApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE", + Expected: &WorkspaceApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + ApiId: "aPiIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceApiIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestSegmentsForWorkspaceApiId(t *testing.T) { + segments := WorkspaceApiId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceApiId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apirevision/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/apirevision/method_listbyservice.go new file mode 100644 index 00000000000..1f1a5af6d1d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirevision/method_listbyservice.go @@ -0,0 +1,141 @@ +package apirevision + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ApiRevisionContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ApiRevisionContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c ApiRevisionClient) ListByService(ctx context.Context, id ApiId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/revisions", 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 *[]ApiRevisionContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c ApiRevisionClient) ListByServiceComplete(ctx context.Context, id ApiId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, ApiRevisionContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiRevisionClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ApiId, options ListByServiceOperationOptions, predicate ApiRevisionContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]ApiRevisionContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apirevision/method_workspaceapirevisionlistbyservice.go b/resource-manager/apimanagement/2024-05-01/apirevision/method_workspaceapirevisionlistbyservice.go new file mode 100644 index 00000000000..acc1134979b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirevision/method_workspaceapirevisionlistbyservice.go @@ -0,0 +1,141 @@ +package apirevision + +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 WorkspaceApiRevisionListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ApiRevisionContract +} + +type WorkspaceApiRevisionListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ApiRevisionContract +} + +type WorkspaceApiRevisionListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultWorkspaceApiRevisionListByServiceOperationOptions() WorkspaceApiRevisionListByServiceOperationOptions { + return WorkspaceApiRevisionListByServiceOperationOptions{} +} + +func (o WorkspaceApiRevisionListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceApiRevisionListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiRevisionListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspaceApiRevisionListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceApiRevisionListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceApiRevisionListByService ... +func (c ApiRevisionClient) WorkspaceApiRevisionListByService(ctx context.Context, id WorkspaceApiId, options WorkspaceApiRevisionListByServiceOperationOptions) (result WorkspaceApiRevisionListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspaceApiRevisionListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/revisions", 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 *[]ApiRevisionContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceApiRevisionListByServiceComplete retrieves all the results into a single object +func (c ApiRevisionClient) WorkspaceApiRevisionListByServiceComplete(ctx context.Context, id WorkspaceApiId, options WorkspaceApiRevisionListByServiceOperationOptions) (WorkspaceApiRevisionListByServiceCompleteResult, error) { + return c.WorkspaceApiRevisionListByServiceCompleteMatchingPredicate(ctx, id, options, ApiRevisionContractOperationPredicate{}) +} + +// WorkspaceApiRevisionListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiRevisionClient) WorkspaceApiRevisionListByServiceCompleteMatchingPredicate(ctx context.Context, id WorkspaceApiId, options WorkspaceApiRevisionListByServiceOperationOptions, predicate ApiRevisionContractOperationPredicate) (result WorkspaceApiRevisionListByServiceCompleteResult, err error) { + items := make([]ApiRevisionContract, 0) + + resp, err := c.WorkspaceApiRevisionListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceApiRevisionListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apirevision/model_apirevisioncontract.go b/resource-manager/apimanagement/2024-05-01/apirevision/model_apirevisioncontract.go new file mode 100644 index 00000000000..3c366c0bef2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirevision/model_apirevisioncontract.go @@ -0,0 +1,45 @@ +package apirevision + +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 ApiRevisionContract struct { + ApiId *string `json:"apiId,omitempty"` + ApiRevision *string `json:"apiRevision,omitempty"` + CreatedDateTime *string `json:"createdDateTime,omitempty"` + Description *string `json:"description,omitempty"` + IsCurrent *bool `json:"isCurrent,omitempty"` + IsOnline *bool `json:"isOnline,omitempty"` + PrivateUrl *string `json:"privateUrl,omitempty"` + UpdatedDateTime *string `json:"updatedDateTime,omitempty"` +} + +func (o *ApiRevisionContract) GetCreatedDateTimeAsTime() (*time.Time, error) { + if o.CreatedDateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedDateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ApiRevisionContract) SetCreatedDateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedDateTime = &formatted +} + +func (o *ApiRevisionContract) GetUpdatedDateTimeAsTime() (*time.Time, error) { + if o.UpdatedDateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.UpdatedDateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ApiRevisionContract) SetUpdatedDateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.UpdatedDateTime = &formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/apirevision/predicates.go b/resource-manager/apimanagement/2024-05-01/apirevision/predicates.go new file mode 100644 index 00000000000..bd4911829a3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirevision/predicates.go @@ -0,0 +1,52 @@ +package apirevision + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiRevisionContractOperationPredicate struct { + ApiId *string + ApiRevision *string + CreatedDateTime *string + Description *string + IsCurrent *bool + IsOnline *bool + PrivateUrl *string + UpdatedDateTime *string +} + +func (p ApiRevisionContractOperationPredicate) Matches(input ApiRevisionContract) bool { + + if p.ApiId != nil && (input.ApiId == nil || *p.ApiId != *input.ApiId) { + return false + } + + if p.ApiRevision != nil && (input.ApiRevision == nil || *p.ApiRevision != *input.ApiRevision) { + return false + } + + if p.CreatedDateTime != nil && (input.CreatedDateTime == nil || *p.CreatedDateTime != *input.CreatedDateTime) { + return false + } + + if p.Description != nil && (input.Description == nil || *p.Description != *input.Description) { + return false + } + + if p.IsCurrent != nil && (input.IsCurrent == nil || *p.IsCurrent != *input.IsCurrent) { + return false + } + + if p.IsOnline != nil && (input.IsOnline == nil || *p.IsOnline != *input.IsOnline) { + return false + } + + if p.PrivateUrl != nil && (input.PrivateUrl == nil || *p.PrivateUrl != *input.PrivateUrl) { + return false + } + + if p.UpdatedDateTime != nil && (input.UpdatedDateTime == nil || *p.UpdatedDateTime != *input.UpdatedDateTime) { + return false + } + + return true +} diff --git a/resource-manager/apimanagement/2024-05-01/apirevision/version.go b/resource-manager/apimanagement/2024-05-01/apirevision/version.go new file mode 100644 index 00000000000..f3936508f5d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apirevision/version.go @@ -0,0 +1,12 @@ +package apirevision + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apirevision/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apisbytag/README.md b/resource-manager/apimanagement/2024-05-01/apisbytag/README.md new file mode 100644 index 00000000000..6657db0caef --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apisbytag/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apisbytag` Documentation + +The `apisbytag` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apisbytag" +``` + + +### Client Initialization + +```go +client := apisbytag.NewApisByTagClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApisByTagClient.ApiListByTags` + +```go +ctx := context.TODO() +id := apisbytag.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ApiListByTags(ctx, id, apisbytag.DefaultApiListByTagsOperationOptions())` can be used to do batched pagination +items, err := client.ApiListByTagsComplete(ctx, id, apisbytag.DefaultApiListByTagsOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/apisbytag/client.go b/resource-manager/apimanagement/2024-05-01/apisbytag/client.go new file mode 100644 index 00000000000..034b78c6308 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apisbytag/client.go @@ -0,0 +1,26 @@ +package apisbytag + +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 ApisByTagClient struct { + Client *resourcemanager.Client +} + +func NewApisByTagClientWithBaseURI(sdkApi sdkEnv.Api) (*ApisByTagClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apisbytag", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApisByTagClient: %+v", err) + } + + return &ApisByTagClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apisbytag/constants.go b/resource-manager/apimanagement/2024-05-01/apisbytag/constants.go new file mode 100644 index 00000000000..0289192099b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apisbytag/constants.go @@ -0,0 +1,192 @@ +package apisbytag + +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 ApiType string + +const ( + ApiTypeGraphql ApiType = "graphql" + ApiTypeGrpc ApiType = "grpc" + ApiTypeHTTP ApiType = "http" + ApiTypeOdata ApiType = "odata" + ApiTypeSoap ApiType = "soap" + ApiTypeWebsocket ApiType = "websocket" +) + +func PossibleValuesForApiType() []string { + return []string{ + string(ApiTypeGraphql), + string(ApiTypeGrpc), + string(ApiTypeHTTP), + string(ApiTypeOdata), + string(ApiTypeSoap), + string(ApiTypeWebsocket), + } +} + +func (s *ApiType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseApiType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseApiType(input string) (*ApiType, error) { + vals := map[string]ApiType{ + "graphql": ApiTypeGraphql, + "grpc": ApiTypeGrpc, + "http": ApiTypeHTTP, + "odata": ApiTypeOdata, + "soap": ApiTypeSoap, + "websocket": ApiTypeWebsocket, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ApiType(input) + return &out, nil +} + +type BearerTokenSendingMethods string + +const ( + BearerTokenSendingMethodsAuthorizationHeader BearerTokenSendingMethods = "authorizationHeader" + BearerTokenSendingMethodsQuery BearerTokenSendingMethods = "query" +) + +func PossibleValuesForBearerTokenSendingMethods() []string { + return []string{ + string(BearerTokenSendingMethodsAuthorizationHeader), + string(BearerTokenSendingMethodsQuery), + } +} + +func (s *BearerTokenSendingMethods) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBearerTokenSendingMethods(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBearerTokenSendingMethods(input string) (*BearerTokenSendingMethods, error) { + vals := map[string]BearerTokenSendingMethods{ + "authorizationheader": BearerTokenSendingMethodsAuthorizationHeader, + "query": BearerTokenSendingMethodsQuery, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BearerTokenSendingMethods(input) + return &out, nil +} + +type ProductState string + +const ( + ProductStateNotPublished ProductState = "notPublished" + ProductStatePublished ProductState = "published" +) + +func PossibleValuesForProductState() []string { + return []string{ + string(ProductStateNotPublished), + string(ProductStatePublished), + } +} + +func (s *ProductState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProductState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProductState(input string) (*ProductState, error) { + vals := map[string]ProductState{ + "notpublished": ProductStateNotPublished, + "published": ProductStatePublished, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProductState(input) + return &out, nil +} + +type Protocol string + +const ( + ProtocolHTTP Protocol = "http" + ProtocolHTTPS Protocol = "https" + ProtocolWs Protocol = "ws" + ProtocolWss Protocol = "wss" +) + +func PossibleValuesForProtocol() []string { + return []string{ + string(ProtocolHTTP), + string(ProtocolHTTPS), + string(ProtocolWs), + string(ProtocolWss), + } +} + +func (s *Protocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProtocol(input string) (*Protocol, error) { + vals := map[string]Protocol{ + "http": ProtocolHTTP, + "https": ProtocolHTTPS, + "ws": ProtocolWs, + "wss": ProtocolWss, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Protocol(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apisbytag/id_service.go b/resource-manager/apimanagement/2024-05-01/apisbytag/id_service.go new file mode 100644 index 00000000000..a88da291012 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apisbytag/id_service.go @@ -0,0 +1,130 @@ +package apisbytag + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apisbytag/id_service_test.go b/resource-manager/apimanagement/2024-05-01/apisbytag/id_service_test.go new file mode 100644 index 00000000000..4104c8240e4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apisbytag/id_service_test.go @@ -0,0 +1,282 @@ +package apisbytag + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apisbytag/method_apilistbytags.go b/resource-manager/apimanagement/2024-05-01/apisbytag/method_apilistbytags.go new file mode 100644 index 00000000000..913e89cf621 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apisbytag/method_apilistbytags.go @@ -0,0 +1,145 @@ +package apisbytag + +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 ApiListByTagsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TagResourceContract +} + +type ApiListByTagsCompleteResult struct { + LatestHttpResponse *http.Response + Items []TagResourceContract +} + +type ApiListByTagsOperationOptions struct { + Filter *string + IncludeNotTaggedApis *bool + Skip *int64 + Top *int64 +} + +func DefaultApiListByTagsOperationOptions() ApiListByTagsOperationOptions { + return ApiListByTagsOperationOptions{} +} + +func (o ApiListByTagsOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ApiListByTagsOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ApiListByTagsOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.IncludeNotTaggedApis != nil { + out.Append("includeNotTaggedApis", fmt.Sprintf("%v", *o.IncludeNotTaggedApis)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ApiListByTagsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ApiListByTagsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ApiListByTags ... +func (c ApisByTagClient) ApiListByTags(ctx context.Context, id ServiceId, options ApiListByTagsOperationOptions) (result ApiListByTagsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ApiListByTagsCustomPager{}, + Path: fmt.Sprintf("%s/apisByTags", 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 *[]TagResourceContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ApiListByTagsComplete retrieves all the results into a single object +func (c ApisByTagClient) ApiListByTagsComplete(ctx context.Context, id ServiceId, options ApiListByTagsOperationOptions) (ApiListByTagsCompleteResult, error) { + return c.ApiListByTagsCompleteMatchingPredicate(ctx, id, options, TagResourceContractOperationPredicate{}) +} + +// ApiListByTagsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApisByTagClient) ApiListByTagsCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ApiListByTagsOperationOptions, predicate TagResourceContractOperationPredicate) (result ApiListByTagsCompleteResult, err error) { + items := make([]TagResourceContract, 0) + + resp, err := c.ApiListByTags(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ApiListByTagsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apisbytag/model_apicontactinformation.go b/resource-manager/apimanagement/2024-05-01/apisbytag/model_apicontactinformation.go new file mode 100644 index 00000000000..0d524fe5d6a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apisbytag/model_apicontactinformation.go @@ -0,0 +1,10 @@ +package apisbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiContactInformation struct { + Email *string `json:"email,omitempty"` + Name *string `json:"name,omitempty"` + Url *string `json:"url,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apisbytag/model_apilicenseinformation.go b/resource-manager/apimanagement/2024-05-01/apisbytag/model_apilicenseinformation.go new file mode 100644 index 00000000000..d882d29ce15 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apisbytag/model_apilicenseinformation.go @@ -0,0 +1,9 @@ +package apisbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiLicenseInformation struct { + Name *string `json:"name,omitempty"` + Url *string `json:"url,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apisbytag/model_apitagresourcecontractproperties.go b/resource-manager/apimanagement/2024-05-01/apisbytag/model_apitagresourcecontractproperties.go new file mode 100644 index 00000000000..33076efa3d1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apisbytag/model_apitagresourcecontractproperties.go @@ -0,0 +1,27 @@ +package apisbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiTagResourceContractProperties struct { + ApiRevision *string `json:"apiRevision,omitempty"` + ApiRevisionDescription *string `json:"apiRevisionDescription,omitempty"` + ApiVersion *string `json:"apiVersion,omitempty"` + ApiVersionDescription *string `json:"apiVersionDescription,omitempty"` + ApiVersionSetId *string `json:"apiVersionSetId,omitempty"` + AuthenticationSettings *AuthenticationSettingsContract `json:"authenticationSettings,omitempty"` + Contact *ApiContactInformation `json:"contact,omitempty"` + Description *string `json:"description,omitempty"` + Id *string `json:"id,omitempty"` + IsCurrent *bool `json:"isCurrent,omitempty"` + IsOnline *bool `json:"isOnline,omitempty"` + License *ApiLicenseInformation `json:"license,omitempty"` + Name *string `json:"name,omitempty"` + Path *string `json:"path,omitempty"` + Protocols *[]Protocol `json:"protocols,omitempty"` + ServiceUrl *string `json:"serviceUrl,omitempty"` + SubscriptionKeyParameterNames *SubscriptionKeyParameterNamesContract `json:"subscriptionKeyParameterNames,omitempty"` + SubscriptionRequired *bool `json:"subscriptionRequired,omitempty"` + TermsOfServiceUrl *string `json:"termsOfServiceUrl,omitempty"` + Type *ApiType `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apisbytag/model_authenticationsettingscontract.go b/resource-manager/apimanagement/2024-05-01/apisbytag/model_authenticationsettingscontract.go new file mode 100644 index 00000000000..af9eff092bd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apisbytag/model_authenticationsettingscontract.go @@ -0,0 +1,11 @@ +package apisbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthenticationSettingsContract struct { + OAuth2 *OAuth2AuthenticationSettingsContract `json:"oAuth2,omitempty"` + OAuth2AuthenticationSettings *[]OAuth2AuthenticationSettingsContract `json:"oAuth2AuthenticationSettings,omitempty"` + Openid *OpenIdAuthenticationSettingsContract `json:"openid,omitempty"` + OpenidAuthenticationSettings *[]OpenIdAuthenticationSettingsContract `json:"openidAuthenticationSettings,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apisbytag/model_oauth2authenticationsettingscontract.go b/resource-manager/apimanagement/2024-05-01/apisbytag/model_oauth2authenticationsettingscontract.go new file mode 100644 index 00000000000..c791c0c14e6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apisbytag/model_oauth2authenticationsettingscontract.go @@ -0,0 +1,9 @@ +package apisbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OAuth2AuthenticationSettingsContract struct { + AuthorizationServerId *string `json:"authorizationServerId,omitempty"` + Scope *string `json:"scope,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apisbytag/model_openidauthenticationsettingscontract.go b/resource-manager/apimanagement/2024-05-01/apisbytag/model_openidauthenticationsettingscontract.go new file mode 100644 index 00000000000..130593f5231 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apisbytag/model_openidauthenticationsettingscontract.go @@ -0,0 +1,9 @@ +package apisbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OpenIdAuthenticationSettingsContract struct { + BearerTokenSendingMethods *[]BearerTokenSendingMethods `json:"bearerTokenSendingMethods,omitempty"` + OpenidProviderId *string `json:"openidProviderId,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apisbytag/model_operationtagresourcecontractproperties.go b/resource-manager/apimanagement/2024-05-01/apisbytag/model_operationtagresourcecontractproperties.go new file mode 100644 index 00000000000..58968b7215c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apisbytag/model_operationtagresourcecontractproperties.go @@ -0,0 +1,15 @@ +package apisbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationTagResourceContractProperties struct { + ApiName *string `json:"apiName,omitempty"` + ApiRevision *string `json:"apiRevision,omitempty"` + ApiVersion *string `json:"apiVersion,omitempty"` + Description *string `json:"description,omitempty"` + Id *string `json:"id,omitempty"` + Method *string `json:"method,omitempty"` + Name *string `json:"name,omitempty"` + UrlTemplate *string `json:"urlTemplate,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apisbytag/model_producttagresourcecontractproperties.go b/resource-manager/apimanagement/2024-05-01/apisbytag/model_producttagresourcecontractproperties.go new file mode 100644 index 00000000000..78a2aa04e14 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apisbytag/model_producttagresourcecontractproperties.go @@ -0,0 +1,15 @@ +package apisbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductTagResourceContractProperties struct { + ApprovalRequired *bool `json:"approvalRequired,omitempty"` + Description *string `json:"description,omitempty"` + Id *string `json:"id,omitempty"` + Name string `json:"name"` + State *ProductState `json:"state,omitempty"` + SubscriptionRequired *bool `json:"subscriptionRequired,omitempty"` + SubscriptionsLimit *int64 `json:"subscriptionsLimit,omitempty"` + Terms *string `json:"terms,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apisbytag/model_subscriptionkeyparameternamescontract.go b/resource-manager/apimanagement/2024-05-01/apisbytag/model_subscriptionkeyparameternamescontract.go new file mode 100644 index 00000000000..9c76b9bf316 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apisbytag/model_subscriptionkeyparameternamescontract.go @@ -0,0 +1,9 @@ +package apisbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionKeyParameterNamesContract struct { + Header *string `json:"header,omitempty"` + Query *string `json:"query,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apisbytag/model_tagresourcecontract.go b/resource-manager/apimanagement/2024-05-01/apisbytag/model_tagresourcecontract.go new file mode 100644 index 00000000000..59b616ee443 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apisbytag/model_tagresourcecontract.go @@ -0,0 +1,11 @@ +package apisbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagResourceContract struct { + Api *ApiTagResourceContractProperties `json:"api,omitempty"` + Operation *OperationTagResourceContractProperties `json:"operation,omitempty"` + Product *ProductTagResourceContractProperties `json:"product,omitempty"` + Tag TagTagResourceContractProperties `json:"tag"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apisbytag/model_tagtagresourcecontractproperties.go b/resource-manager/apimanagement/2024-05-01/apisbytag/model_tagtagresourcecontractproperties.go new file mode 100644 index 00000000000..ff669fa6e2f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apisbytag/model_tagtagresourcecontractproperties.go @@ -0,0 +1,9 @@ +package apisbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagTagResourceContractProperties struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apisbytag/predicates.go b/resource-manager/apimanagement/2024-05-01/apisbytag/predicates.go new file mode 100644 index 00000000000..5a12cb9a284 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apisbytag/predicates.go @@ -0,0 +1,12 @@ +package apisbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagResourceContractOperationPredicate struct { +} + +func (p TagResourceContractOperationPredicate) Matches(input TagResourceContract) bool { + + return true +} diff --git a/resource-manager/apimanagement/2024-05-01/apisbytag/version.go b/resource-manager/apimanagement/2024-05-01/apisbytag/version.go new file mode 100644 index 00000000000..3271979c907 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apisbytag/version.go @@ -0,0 +1,12 @@ +package apisbytag + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apisbytag/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apischema/README.md b/resource-manager/apimanagement/2024-05-01/apischema/README.md new file mode 100644 index 00000000000..7d349279fd9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/README.md @@ -0,0 +1,184 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apischema` Documentation + +The `apischema` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apischema" +``` + + +### Client Initialization + +```go +client := apischema.NewApiSchemaClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiSchemaClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := apischema.NewApiSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "schemaIdValue") + +payload := apischema.SchemaContract{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload, apischema.DefaultCreateOrUpdateOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `ApiSchemaClient.Delete` + +```go +ctx := context.TODO() +id := apischema.NewApiSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "schemaIdValue") + +read, err := client.Delete(ctx, id, apischema.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiSchemaClient.Get` + +```go +ctx := context.TODO() +id := apischema.NewApiSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "schemaIdValue") + +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: `ApiSchemaClient.GetEntityTag` + +```go +ctx := context.TODO() +id := apischema.NewApiSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "schemaIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiSchemaClient.ListByApi` + +```go +ctx := context.TODO() +id := apischema.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +// alternatively `client.ListByApi(ctx, id, apischema.DefaultListByApiOperationOptions())` can be used to do batched pagination +items, err := client.ListByApiComplete(ctx, id, apischema.DefaultListByApiOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ApiSchemaClient.WorkspaceApiSchemaCreateOrUpdate` + +```go +ctx := context.TODO() +id := apischema.NewWorkspaceApiSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "schemaIdValue") + +payload := apischema.SchemaContract{ + // ... +} + + +if err := client.WorkspaceApiSchemaCreateOrUpdateThenPoll(ctx, id, payload, apischema.DefaultWorkspaceApiSchemaCreateOrUpdateOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `ApiSchemaClient.WorkspaceApiSchemaDelete` + +```go +ctx := context.TODO() +id := apischema.NewWorkspaceApiSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "schemaIdValue") + +read, err := client.WorkspaceApiSchemaDelete(ctx, id, apischema.DefaultWorkspaceApiSchemaDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiSchemaClient.WorkspaceApiSchemaGet` + +```go +ctx := context.TODO() +id := apischema.NewWorkspaceApiSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "schemaIdValue") + +read, err := client.WorkspaceApiSchemaGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiSchemaClient.WorkspaceApiSchemaGetEntityTag` + +```go +ctx := context.TODO() +id := apischema.NewWorkspaceApiSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "schemaIdValue") + +read, err := client.WorkspaceApiSchemaGetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiSchemaClient.WorkspaceApiSchemaListByApi` + +```go +ctx := context.TODO() +id := apischema.NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue") + +// alternatively `client.WorkspaceApiSchemaListByApi(ctx, id, apischema.DefaultWorkspaceApiSchemaListByApiOperationOptions())` can be used to do batched pagination +items, err := client.WorkspaceApiSchemaListByApiComplete(ctx, id, apischema.DefaultWorkspaceApiSchemaListByApiOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/apischema/client.go b/resource-manager/apimanagement/2024-05-01/apischema/client.go new file mode 100644 index 00000000000..fb466515328 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/client.go @@ -0,0 +1,26 @@ +package apischema + +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 ApiSchemaClient struct { + Client *resourcemanager.Client +} + +func NewApiSchemaClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiSchemaClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apischema", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiSchemaClient: %+v", err) + } + + return &ApiSchemaClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apischema/id_api.go b/resource-manager/apimanagement/2024-05-01/apischema/id_api.go new file mode 100644 index 00000000000..725dc89049b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/id_api.go @@ -0,0 +1,139 @@ +package apischema + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiId{}) +} + +var _ resourceids.ResourceId = &ApiId{} + +// ApiId is a struct representing the Resource ID for a Api +type ApiId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string +} + +// NewApiID returns a new ApiId struct +func NewApiID(subscriptionId string, resourceGroupName string, serviceName string, apiId string) ApiId { + return ApiId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + } +} + +// ParseApiID parses 'input' into a ApiId +func ParseApiID(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiIDInsensitively parses 'input' case-insensitively into a ApiId +// note: this method should only be used for API response data and not user input +func ParseApiIDInsensitively(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + return nil +} + +// ValidateApiID checks that 'input' can be parsed as a Api ID +func ValidateApiID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api ID +func (id ApiId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api ID +func (id ApiId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + } +} + +// String returns a human-readable description of this Api ID +func (id ApiId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + } + return fmt.Sprintf("Api (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apischema/id_api_test.go b/resource-manager/apimanagement/2024-05-01/apischema/id_api_test.go new file mode 100644 index 00000000000..87cc18dc5cd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/id_api_test.go @@ -0,0 +1,327 @@ +package apischema + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiId{} + +func TestNewApiID(t *testing.T) { + id := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } +} + +func TestFormatApiID(t *testing.T) { + actual := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestParseApiIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestSegmentsForApiId(t *testing.T) { + segments := ApiId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apischema/id_apischema.go b/resource-manager/apimanagement/2024-05-01/apischema/id_apischema.go new file mode 100644 index 00000000000..af8be6866d8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/id_apischema.go @@ -0,0 +1,148 @@ +package apischema + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiSchemaId{}) +} + +var _ resourceids.ResourceId = &ApiSchemaId{} + +// ApiSchemaId is a struct representing the Resource ID for a Api Schema +type ApiSchemaId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string + SchemaId string +} + +// NewApiSchemaID returns a new ApiSchemaId struct +func NewApiSchemaID(subscriptionId string, resourceGroupName string, serviceName string, apiId string, schemaId string) ApiSchemaId { + return ApiSchemaId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + SchemaId: schemaId, + } +} + +// ParseApiSchemaID parses 'input' into a ApiSchemaId +func ParseApiSchemaID(input string) (*ApiSchemaId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiSchemaId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiSchemaId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiSchemaIDInsensitively parses 'input' case-insensitively into a ApiSchemaId +// note: this method should only be used for API response data and not user input +func ParseApiSchemaIDInsensitively(input string) (*ApiSchemaId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiSchemaId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiSchemaId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiSchemaId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + if id.SchemaId, ok = input.Parsed["schemaId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaId", input) + } + + return nil +} + +// ValidateApiSchemaID checks that 'input' can be parsed as a Api Schema ID +func ValidateApiSchemaID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiSchemaID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api Schema ID +func (id ApiSchemaId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s/schemas/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId, id.SchemaId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api Schema ID +func (id ApiSchemaId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaId", "schemaIdValue"), + } +} + +// String returns a human-readable description of this Api Schema ID +func (id ApiSchemaId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + fmt.Sprintf("Schema: %q", id.SchemaId), + } + return fmt.Sprintf("Api Schema (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apischema/id_apischema_test.go b/resource-manager/apimanagement/2024-05-01/apischema/id_apischema_test.go new file mode 100644 index 00000000000..5ff581bd680 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/id_apischema_test.go @@ -0,0 +1,372 @@ +package apischema + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiSchemaId{} + +func TestNewApiSchemaID(t *testing.T) { + id := NewApiSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "schemaIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } + + if id.SchemaId != "schemaIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaId'", id.SchemaId, "schemaIdValue") + } +} + +func TestFormatApiSchemaID(t *testing.T) { + actual := NewApiSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "schemaIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/schemas/schemaIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiSchemaID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiSchemaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/schemas", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/schemas/schemaIdValue", + Expected: &ApiSchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + SchemaId: "schemaIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/schemas/schemaIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiSchemaID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.SchemaId != v.Expected.SchemaId { + t.Fatalf("Expected %q but got %q for SchemaId", v.Expected.SchemaId, actual.SchemaId) + } + + } +} + +func TestParseApiSchemaIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiSchemaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/sChEmAs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/schemas/schemaIdValue", + Expected: &ApiSchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + SchemaId: "schemaIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/schemas/schemaIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/sChEmAs/sChEmAiDvAlUe", + Expected: &ApiSchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + SchemaId: "sChEmAiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/sChEmAs/sChEmAiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiSchemaIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.SchemaId != v.Expected.SchemaId { + t.Fatalf("Expected %q but got %q for SchemaId", v.Expected.SchemaId, actual.SchemaId) + } + + } +} + +func TestSegmentsForApiSchemaId(t *testing.T) { + segments := ApiSchemaId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiSchemaId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apischema/id_workspaceapi.go b/resource-manager/apimanagement/2024-05-01/apischema/id_workspaceapi.go new file mode 100644 index 00000000000..a3b95e32e10 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/id_workspaceapi.go @@ -0,0 +1,148 @@ +package apischema + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceApiId{}) +} + +var _ resourceids.ResourceId = &WorkspaceApiId{} + +// WorkspaceApiId is a struct representing the Resource ID for a Workspace Api +type WorkspaceApiId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + ApiId string +} + +// NewWorkspaceApiID returns a new WorkspaceApiId struct +func NewWorkspaceApiID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, apiId string) WorkspaceApiId { + return WorkspaceApiId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + ApiId: apiId, + } +} + +// ParseWorkspaceApiID parses 'input' into a WorkspaceApiId +func ParseWorkspaceApiID(input string) (*WorkspaceApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceApiId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceApiIDInsensitively parses 'input' case-insensitively into a WorkspaceApiId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceApiIDInsensitively(input string) (*WorkspaceApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceApiId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceApiId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + return nil +} + +// ValidateWorkspaceApiID checks that 'input' can be parsed as a Workspace Api ID +func ValidateWorkspaceApiID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceApiID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Api ID +func (id WorkspaceApiId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/apis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.ApiId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Api ID +func (id WorkspaceApiId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + } +} + +// String returns a human-readable description of this Workspace Api ID +func (id WorkspaceApiId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Api: %q", id.ApiId), + } + return fmt.Sprintf("Workspace Api (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apischema/id_workspaceapi_test.go b/resource-manager/apimanagement/2024-05-01/apischema/id_workspaceapi_test.go new file mode 100644 index 00000000000..4daef66b7e5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/id_workspaceapi_test.go @@ -0,0 +1,372 @@ +package apischema + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceApiId{} + +func TestNewWorkspaceApiID(t *testing.T) { + id := NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } +} + +func TestFormatWorkspaceApiID(t *testing.T) { + actual := NewWorkspaceApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceApiID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue", + Expected: &WorkspaceApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceApiID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestParseWorkspaceApiIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue", + Expected: &WorkspaceApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE", + Expected: &WorkspaceApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + ApiId: "aPiIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceApiIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestSegmentsForWorkspaceApiId(t *testing.T) { + segments := WorkspaceApiId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceApiId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apischema/id_workspaceapischema.go b/resource-manager/apimanagement/2024-05-01/apischema/id_workspaceapischema.go new file mode 100644 index 00000000000..2b8ca6ceea1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/id_workspaceapischema.go @@ -0,0 +1,157 @@ +package apischema + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceApiSchemaId{}) +} + +var _ resourceids.ResourceId = &WorkspaceApiSchemaId{} + +// WorkspaceApiSchemaId is a struct representing the Resource ID for a Workspace Api Schema +type WorkspaceApiSchemaId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + ApiId string + SchemaId string +} + +// NewWorkspaceApiSchemaID returns a new WorkspaceApiSchemaId struct +func NewWorkspaceApiSchemaID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, apiId string, schemaId string) WorkspaceApiSchemaId { + return WorkspaceApiSchemaId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + ApiId: apiId, + SchemaId: schemaId, + } +} + +// ParseWorkspaceApiSchemaID parses 'input' into a WorkspaceApiSchemaId +func ParseWorkspaceApiSchemaID(input string) (*WorkspaceApiSchemaId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceApiSchemaId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceApiSchemaId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceApiSchemaIDInsensitively parses 'input' case-insensitively into a WorkspaceApiSchemaId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceApiSchemaIDInsensitively(input string) (*WorkspaceApiSchemaId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceApiSchemaId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceApiSchemaId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceApiSchemaId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + if id.SchemaId, ok = input.Parsed["schemaId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaId", input) + } + + return nil +} + +// ValidateWorkspaceApiSchemaID checks that 'input' can be parsed as a Workspace Api Schema ID +func ValidateWorkspaceApiSchemaID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceApiSchemaID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Api Schema ID +func (id WorkspaceApiSchemaId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/apis/%s/schemas/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.ApiId, id.SchemaId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Api Schema ID +func (id WorkspaceApiSchemaId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaId", "schemaIdValue"), + } +} + +// String returns a human-readable description of this Workspace Api Schema ID +func (id WorkspaceApiSchemaId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Api: %q", id.ApiId), + fmt.Sprintf("Schema: %q", id.SchemaId), + } + return fmt.Sprintf("Workspace Api Schema (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apischema/id_workspaceapischema_test.go b/resource-manager/apimanagement/2024-05-01/apischema/id_workspaceapischema_test.go new file mode 100644 index 00000000000..9403937f88f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/id_workspaceapischema_test.go @@ -0,0 +1,417 @@ +package apischema + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceApiSchemaId{} + +func TestNewWorkspaceApiSchemaID(t *testing.T) { + id := NewWorkspaceApiSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "schemaIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } + + if id.SchemaId != "schemaIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaId'", id.SchemaId, "schemaIdValue") + } +} + +func TestFormatWorkspaceApiSchemaID(t *testing.T) { + actual := NewWorkspaceApiSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "apiIdValue", "schemaIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/schemas/schemaIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceApiSchemaID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceApiSchemaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/schemas", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/schemas/schemaIdValue", + Expected: &WorkspaceApiSchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ApiId: "apiIdValue", + SchemaId: "schemaIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/schemas/schemaIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceApiSchemaID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.SchemaId != v.Expected.SchemaId { + t.Fatalf("Expected %q but got %q for SchemaId", v.Expected.SchemaId, actual.SchemaId) + } + + } +} + +func TestParseWorkspaceApiSchemaIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceApiSchemaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE/sChEmAs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/schemas/schemaIdValue", + Expected: &WorkspaceApiSchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ApiId: "apiIdValue", + SchemaId: "schemaIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apis/apiIdValue/schemas/schemaIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE/sChEmAs/sChEmAiDvAlUe", + Expected: &WorkspaceApiSchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + ApiId: "aPiIdVaLuE", + SchemaId: "sChEmAiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiS/aPiIdVaLuE/sChEmAs/sChEmAiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceApiSchemaIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.SchemaId != v.Expected.SchemaId { + t.Fatalf("Expected %q but got %q for SchemaId", v.Expected.SchemaId, actual.SchemaId) + } + + } +} + +func TestSegmentsForWorkspaceApiSchemaId(t *testing.T) { + segments := WorkspaceApiSchemaId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceApiSchemaId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apischema/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/apischema/method_createorupdate.go new file mode 100644 index 00000000000..6d09c53ad77 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/method_createorupdate.go @@ -0,0 +1,103 @@ +package apischema + +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 *SchemaContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c ApiSchemaClient) CreateOrUpdate(ctx context.Context, id ApiSchemaId, input SchemaContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 ApiSchemaClient) CreateOrUpdateThenPoll(ctx context.Context, id ApiSchemaId, input SchemaContract, options CreateOrUpdateOperationOptions) error { + result, err := c.CreateOrUpdate(ctx, id, input, options) + 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/apimanagement/2024-05-01/apischema/method_delete.go b/resource-manager/apimanagement/2024-05-01/apischema/method_delete.go new file mode 100644 index 00000000000..1e1272fa389 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/method_delete.go @@ -0,0 +1,79 @@ +package apischema + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + Force *bool + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Force != nil { + out.Append("force", fmt.Sprintf("%v", *o.Force)) + } + return &out +} + +// Delete ... +func (c ApiSchemaClient) Delete(ctx context.Context, id ApiSchemaId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apischema/method_get.go b/resource-manager/apimanagement/2024-05-01/apischema/method_get.go new file mode 100644 index 00000000000..c0bd56818fa --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/method_get.go @@ -0,0 +1,54 @@ +package apischema + +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 *SchemaContract +} + +// Get ... +func (c ApiSchemaClient) Get(ctx context.Context, id ApiSchemaId) (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 SchemaContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apischema/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/apischema/method_getentitytag.go new file mode 100644 index 00000000000..06aa5ede3ba --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/method_getentitytag.go @@ -0,0 +1,46 @@ +package apischema + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c ApiSchemaClient) GetEntityTag(ctx context.Context, id ApiSchemaId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apischema/method_listbyapi.go b/resource-manager/apimanagement/2024-05-01/apischema/method_listbyapi.go new file mode 100644 index 00000000000..c3cb801dfce --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/method_listbyapi.go @@ -0,0 +1,141 @@ +package apischema + +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 ListByApiOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SchemaContract +} + +type ListByApiCompleteResult struct { + LatestHttpResponse *http.Response + Items []SchemaContract +} + +type ListByApiOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByApiOperationOptions() ListByApiOperationOptions { + return ListByApiOperationOptions{} +} + +func (o ListByApiOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByApiOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByApiOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByApiCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByApiCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByApi ... +func (c ApiSchemaClient) ListByApi(ctx context.Context, id ApiId, options ListByApiOperationOptions) (result ListByApiOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByApiCustomPager{}, + Path: fmt.Sprintf("%s/schemas", 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 *[]SchemaContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByApiComplete retrieves all the results into a single object +func (c ApiSchemaClient) ListByApiComplete(ctx context.Context, id ApiId, options ListByApiOperationOptions) (ListByApiCompleteResult, error) { + return c.ListByApiCompleteMatchingPredicate(ctx, id, options, SchemaContractOperationPredicate{}) +} + +// ListByApiCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiSchemaClient) ListByApiCompleteMatchingPredicate(ctx context.Context, id ApiId, options ListByApiOperationOptions, predicate SchemaContractOperationPredicate) (result ListByApiCompleteResult, err error) { + items := make([]SchemaContract, 0) + + resp, err := c.ListByApi(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByApiCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apischema/method_workspaceapischemacreateorupdate.go b/resource-manager/apimanagement/2024-05-01/apischema/method_workspaceapischemacreateorupdate.go new file mode 100644 index 00000000000..86ee733c704 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/method_workspaceapischemacreateorupdate.go @@ -0,0 +1,103 @@ +package apischema + +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 WorkspaceApiSchemaCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *SchemaContract +} + +type WorkspaceApiSchemaCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceApiSchemaCreateOrUpdateOperationOptions() WorkspaceApiSchemaCreateOrUpdateOperationOptions { + return WorkspaceApiSchemaCreateOrUpdateOperationOptions{} +} + +func (o WorkspaceApiSchemaCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceApiSchemaCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiSchemaCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceApiSchemaCreateOrUpdate ... +func (c ApiSchemaClient) WorkspaceApiSchemaCreateOrUpdate(ctx context.Context, id WorkspaceApiSchemaId, input SchemaContract, options WorkspaceApiSchemaCreateOrUpdateOperationOptions) (result WorkspaceApiSchemaCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 +} + +// WorkspaceApiSchemaCreateOrUpdateThenPoll performs WorkspaceApiSchemaCreateOrUpdate then polls until it's completed +func (c ApiSchemaClient) WorkspaceApiSchemaCreateOrUpdateThenPoll(ctx context.Context, id WorkspaceApiSchemaId, input SchemaContract, options WorkspaceApiSchemaCreateOrUpdateOperationOptions) error { + result, err := c.WorkspaceApiSchemaCreateOrUpdate(ctx, id, input, options) + if err != nil { + return fmt.Errorf("performing WorkspaceApiSchemaCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after WorkspaceApiSchemaCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apischema/method_workspaceapischemadelete.go b/resource-manager/apimanagement/2024-05-01/apischema/method_workspaceapischemadelete.go new file mode 100644 index 00000000000..f5c12caff48 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/method_workspaceapischemadelete.go @@ -0,0 +1,79 @@ +package apischema + +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 WorkspaceApiSchemaDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type WorkspaceApiSchemaDeleteOperationOptions struct { + Force *bool + IfMatch *string +} + +func DefaultWorkspaceApiSchemaDeleteOperationOptions() WorkspaceApiSchemaDeleteOperationOptions { + return WorkspaceApiSchemaDeleteOperationOptions{} +} + +func (o WorkspaceApiSchemaDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceApiSchemaDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiSchemaDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Force != nil { + out.Append("force", fmt.Sprintf("%v", *o.Force)) + } + return &out +} + +// WorkspaceApiSchemaDelete ... +func (c ApiSchemaClient) WorkspaceApiSchemaDelete(ctx context.Context, id WorkspaceApiSchemaId, options WorkspaceApiSchemaDeleteOperationOptions) (result WorkspaceApiSchemaDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apischema/method_workspaceapischemaget.go b/resource-manager/apimanagement/2024-05-01/apischema/method_workspaceapischemaget.go new file mode 100644 index 00000000000..0e2e9ec7b07 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/method_workspaceapischemaget.go @@ -0,0 +1,54 @@ +package apischema + +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 WorkspaceApiSchemaGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SchemaContract +} + +// WorkspaceApiSchemaGet ... +func (c ApiSchemaClient) WorkspaceApiSchemaGet(ctx context.Context, id WorkspaceApiSchemaId) (result WorkspaceApiSchemaGetOperationResponse, 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 SchemaContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apischema/method_workspaceapischemagetentitytag.go b/resource-manager/apimanagement/2024-05-01/apischema/method_workspaceapischemagetentitytag.go new file mode 100644 index 00000000000..5d2d0fb6d6f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/method_workspaceapischemagetentitytag.go @@ -0,0 +1,46 @@ +package apischema + +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 WorkspaceApiSchemaGetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceApiSchemaGetEntityTag ... +func (c ApiSchemaClient) WorkspaceApiSchemaGetEntityTag(ctx context.Context, id WorkspaceApiSchemaId) (result WorkspaceApiSchemaGetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apischema/method_workspaceapischemalistbyapi.go b/resource-manager/apimanagement/2024-05-01/apischema/method_workspaceapischemalistbyapi.go new file mode 100644 index 00000000000..df9c59dfaf8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/method_workspaceapischemalistbyapi.go @@ -0,0 +1,141 @@ +package apischema + +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 WorkspaceApiSchemaListByApiOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SchemaContract +} + +type WorkspaceApiSchemaListByApiCompleteResult struct { + LatestHttpResponse *http.Response + Items []SchemaContract +} + +type WorkspaceApiSchemaListByApiOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultWorkspaceApiSchemaListByApiOperationOptions() WorkspaceApiSchemaListByApiOperationOptions { + return WorkspaceApiSchemaListByApiOperationOptions{} +} + +func (o WorkspaceApiSchemaListByApiOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceApiSchemaListByApiOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiSchemaListByApiOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspaceApiSchemaListByApiCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceApiSchemaListByApiCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceApiSchemaListByApi ... +func (c ApiSchemaClient) WorkspaceApiSchemaListByApi(ctx context.Context, id WorkspaceApiId, options WorkspaceApiSchemaListByApiOperationOptions) (result WorkspaceApiSchemaListByApiOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspaceApiSchemaListByApiCustomPager{}, + Path: fmt.Sprintf("%s/schemas", 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 *[]SchemaContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceApiSchemaListByApiComplete retrieves all the results into a single object +func (c ApiSchemaClient) WorkspaceApiSchemaListByApiComplete(ctx context.Context, id WorkspaceApiId, options WorkspaceApiSchemaListByApiOperationOptions) (WorkspaceApiSchemaListByApiCompleteResult, error) { + return c.WorkspaceApiSchemaListByApiCompleteMatchingPredicate(ctx, id, options, SchemaContractOperationPredicate{}) +} + +// WorkspaceApiSchemaListByApiCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiSchemaClient) WorkspaceApiSchemaListByApiCompleteMatchingPredicate(ctx context.Context, id WorkspaceApiId, options WorkspaceApiSchemaListByApiOperationOptions, predicate SchemaContractOperationPredicate) (result WorkspaceApiSchemaListByApiCompleteResult, err error) { + items := make([]SchemaContract, 0) + + resp, err := c.WorkspaceApiSchemaListByApi(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceApiSchemaListByApiCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apischema/model_schemacontract.go b/resource-manager/apimanagement/2024-05-01/apischema/model_schemacontract.go new file mode 100644 index 00000000000..784220164fd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/model_schemacontract.go @@ -0,0 +1,11 @@ +package apischema + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SchemaContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SchemaContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apischema/model_schemacontractproperties.go b/resource-manager/apimanagement/2024-05-01/apischema/model_schemacontractproperties.go new file mode 100644 index 00000000000..d96a1fa1b65 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/model_schemacontractproperties.go @@ -0,0 +1,10 @@ +package apischema + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SchemaContractProperties struct { + ContentType string `json:"contentType"` + Document SchemaDocumentProperties `json:"document"` + ProvisioningState *string `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apischema/model_schemadocumentproperties.go b/resource-manager/apimanagement/2024-05-01/apischema/model_schemadocumentproperties.go new file mode 100644 index 00000000000..bf00fb63435 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/model_schemadocumentproperties.go @@ -0,0 +1,10 @@ +package apischema + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SchemaDocumentProperties struct { + Components *interface{} `json:"components,omitempty"` + Definitions *interface{} `json:"definitions,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apischema/predicates.go b/resource-manager/apimanagement/2024-05-01/apischema/predicates.go new file mode 100644 index 00000000000..2805a46671c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/predicates.go @@ -0,0 +1,27 @@ +package apischema + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SchemaContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SchemaContractOperationPredicate) Matches(input SchemaContract) 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/apimanagement/2024-05-01/apischema/version.go b/resource-manager/apimanagement/2024-05-01/apischema/version.go new file mode 100644 index 00000000000..77d8ed01019 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apischema/version.go @@ -0,0 +1,12 @@ +package apischema + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apischema/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apitag/README.md b/resource-manager/apimanagement/2024-05-01/apitag/README.md new file mode 100644 index 00000000000..08383af522f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitag/README.md @@ -0,0 +1,101 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apitag` Documentation + +The `apitag` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apitag" +``` + + +### Client Initialization + +```go +client := apitag.NewApiTagClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiTagClient.TagAssignToApi` + +```go +ctx := context.TODO() +id := apitag.NewApiTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "tagIdValue") + +read, err := client.TagAssignToApi(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiTagClient.TagDetachFromApi` + +```go +ctx := context.TODO() +id := apitag.NewApiTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "tagIdValue") + +read, err := client.TagDetachFromApi(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiTagClient.TagGetByApi` + +```go +ctx := context.TODO() +id := apitag.NewApiTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "tagIdValue") + +read, err := client.TagGetByApi(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiTagClient.TagGetEntityStateByApi` + +```go +ctx := context.TODO() +id := apitag.NewApiTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "tagIdValue") + +read, err := client.TagGetEntityStateByApi(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiTagClient.TagListByApi` + +```go +ctx := context.TODO() +id := apitag.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +// alternatively `client.TagListByApi(ctx, id, apitag.DefaultTagListByApiOperationOptions())` can be used to do batched pagination +items, err := client.TagListByApiComplete(ctx, id, apitag.DefaultTagListByApiOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/apitag/client.go b/resource-manager/apimanagement/2024-05-01/apitag/client.go new file mode 100644 index 00000000000..491411cb346 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitag/client.go @@ -0,0 +1,26 @@ +package apitag + +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 ApiTagClient struct { + Client *resourcemanager.Client +} + +func NewApiTagClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiTagClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apitag", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiTagClient: %+v", err) + } + + return &ApiTagClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apitag/id_api.go b/resource-manager/apimanagement/2024-05-01/apitag/id_api.go new file mode 100644 index 00000000000..584293d60e3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitag/id_api.go @@ -0,0 +1,139 @@ +package apitag + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiId{}) +} + +var _ resourceids.ResourceId = &ApiId{} + +// ApiId is a struct representing the Resource ID for a Api +type ApiId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string +} + +// NewApiID returns a new ApiId struct +func NewApiID(subscriptionId string, resourceGroupName string, serviceName string, apiId string) ApiId { + return ApiId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + } +} + +// ParseApiID parses 'input' into a ApiId +func ParseApiID(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiIDInsensitively parses 'input' case-insensitively into a ApiId +// note: this method should only be used for API response data and not user input +func ParseApiIDInsensitively(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + return nil +} + +// ValidateApiID checks that 'input' can be parsed as a Api ID +func ValidateApiID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api ID +func (id ApiId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api ID +func (id ApiId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + } +} + +// String returns a human-readable description of this Api ID +func (id ApiId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + } + return fmt.Sprintf("Api (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apitag/id_api_test.go b/resource-manager/apimanagement/2024-05-01/apitag/id_api_test.go new file mode 100644 index 00000000000..bd9c7702e2c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitag/id_api_test.go @@ -0,0 +1,327 @@ +package apitag + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiId{} + +func TestNewApiID(t *testing.T) { + id := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } +} + +func TestFormatApiID(t *testing.T) { + actual := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestParseApiIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestSegmentsForApiId(t *testing.T) { + segments := ApiId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apitag/id_apitag.go b/resource-manager/apimanagement/2024-05-01/apitag/id_apitag.go new file mode 100644 index 00000000000..13e9a7f8c96 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitag/id_apitag.go @@ -0,0 +1,148 @@ +package apitag + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiTagId{}) +} + +var _ resourceids.ResourceId = &ApiTagId{} + +// ApiTagId is a struct representing the Resource ID for a Api Tag +type ApiTagId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string + TagId string +} + +// NewApiTagID returns a new ApiTagId struct +func NewApiTagID(subscriptionId string, resourceGroupName string, serviceName string, apiId string, tagId string) ApiTagId { + return ApiTagId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + TagId: tagId, + } +} + +// ParseApiTagID parses 'input' into a ApiTagId +func ParseApiTagID(input string) (*ApiTagId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiTagId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiTagId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiTagIDInsensitively parses 'input' case-insensitively into a ApiTagId +// note: this method should only be used for API response data and not user input +func ParseApiTagIDInsensitively(input string) (*ApiTagId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiTagId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiTagId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiTagId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + if id.TagId, ok = input.Parsed["tagId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagId", input) + } + + return nil +} + +// ValidateApiTagID checks that 'input' can be parsed as a Api Tag ID +func ValidateApiTagID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiTagID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api Tag ID +func (id ApiTagId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s/tags/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId, id.TagId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api Tag ID +func (id ApiTagId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + resourceids.StaticSegment("staticTags", "tags", "tags"), + resourceids.UserSpecifiedSegment("tagId", "tagIdValue"), + } +} + +// String returns a human-readable description of this Api Tag ID +func (id ApiTagId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + fmt.Sprintf("Tag: %q", id.TagId), + } + return fmt.Sprintf("Api Tag (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apitag/id_apitag_test.go b/resource-manager/apimanagement/2024-05-01/apitag/id_apitag_test.go new file mode 100644 index 00000000000..568a91fdda8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitag/id_apitag_test.go @@ -0,0 +1,372 @@ +package apitag + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiTagId{} + +func TestNewApiTagID(t *testing.T) { + id := NewApiTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "tagIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } + + if id.TagId != "tagIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'TagId'", id.TagId, "tagIdValue") + } +} + +func TestFormatApiTagID(t *testing.T) { + actual := NewApiTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "tagIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/tags/tagIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiTagID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiTagId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/tags", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/tags/tagIdValue", + Expected: &ApiTagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + TagId: "tagIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/tags/tagIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiTagID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + } +} + +func TestParseApiTagIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiTagId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/tags", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/tAgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/tags/tagIdValue", + Expected: &ApiTagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + TagId: "tagIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/tags/tagIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/tAgS/tAgIdVaLuE", + Expected: &ApiTagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + TagId: "tAgIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/tAgS/tAgIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiTagIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + } +} + +func TestSegmentsForApiTagId(t *testing.T) { + segments := ApiTagId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiTagId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apitag/method_tagassigntoapi.go b/resource-manager/apimanagement/2024-05-01/apitag/method_tagassigntoapi.go new file mode 100644 index 00000000000..daa3d8e3cbb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitag/method_tagassigntoapi.go @@ -0,0 +1,55 @@ +package apitag + +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 TagAssignToApiOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TagContract +} + +// TagAssignToApi ... +func (c ApiTagClient) TagAssignToApi(ctx context.Context, id ApiTagId) (result TagAssignToApiOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model TagContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apitag/method_tagdetachfromapi.go b/resource-manager/apimanagement/2024-05-01/apitag/method_tagdetachfromapi.go new file mode 100644 index 00000000000..ad546cf7c3c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitag/method_tagdetachfromapi.go @@ -0,0 +1,47 @@ +package apitag + +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 TagDetachFromApiOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// TagDetachFromApi ... +func (c ApiTagClient) TagDetachFromApi(ctx context.Context, id ApiTagId) (result TagDetachFromApiOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apitag/method_taggetbyapi.go b/resource-manager/apimanagement/2024-05-01/apitag/method_taggetbyapi.go new file mode 100644 index 00000000000..17951c4564a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitag/method_taggetbyapi.go @@ -0,0 +1,54 @@ +package apitag + +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 TagGetByApiOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TagContract +} + +// TagGetByApi ... +func (c ApiTagClient) TagGetByApi(ctx context.Context, id ApiTagId) (result TagGetByApiOperationResponse, 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 TagContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apitag/method_taggetentitystatebyapi.go b/resource-manager/apimanagement/2024-05-01/apitag/method_taggetentitystatebyapi.go new file mode 100644 index 00000000000..eb833e96b2a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitag/method_taggetentitystatebyapi.go @@ -0,0 +1,46 @@ +package apitag + +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 TagGetEntityStateByApiOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// TagGetEntityStateByApi ... +func (c ApiTagClient) TagGetEntityStateByApi(ctx context.Context, id ApiTagId) (result TagGetEntityStateByApiOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apitag/method_taglistbyapi.go b/resource-manager/apimanagement/2024-05-01/apitag/method_taglistbyapi.go new file mode 100644 index 00000000000..5c2639c91e3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitag/method_taglistbyapi.go @@ -0,0 +1,141 @@ +package apitag + +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 TagListByApiOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TagContract +} + +type TagListByApiCompleteResult struct { + LatestHttpResponse *http.Response + Items []TagContract +} + +type TagListByApiOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultTagListByApiOperationOptions() TagListByApiOperationOptions { + return TagListByApiOperationOptions{} +} + +func (o TagListByApiOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o TagListByApiOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o TagListByApiOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type TagListByApiCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *TagListByApiCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// TagListByApi ... +func (c ApiTagClient) TagListByApi(ctx context.Context, id ApiId, options TagListByApiOperationOptions) (result TagListByApiOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &TagListByApiCustomPager{}, + Path: fmt.Sprintf("%s/tags", 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 *[]TagContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// TagListByApiComplete retrieves all the results into a single object +func (c ApiTagClient) TagListByApiComplete(ctx context.Context, id ApiId, options TagListByApiOperationOptions) (TagListByApiCompleteResult, error) { + return c.TagListByApiCompleteMatchingPredicate(ctx, id, options, TagContractOperationPredicate{}) +} + +// TagListByApiCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiTagClient) TagListByApiCompleteMatchingPredicate(ctx context.Context, id ApiId, options TagListByApiOperationOptions, predicate TagContractOperationPredicate) (result TagListByApiCompleteResult, err error) { + items := make([]TagContract, 0) + + resp, err := c.TagListByApi(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = TagListByApiCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apitag/model_tagcontract.go b/resource-manager/apimanagement/2024-05-01/apitag/model_tagcontract.go new file mode 100644 index 00000000000..3bcb3a6a462 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitag/model_tagcontract.go @@ -0,0 +1,11 @@ +package apitag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *TagContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apitag/model_tagcontractproperties.go b/resource-manager/apimanagement/2024-05-01/apitag/model_tagcontractproperties.go new file mode 100644 index 00000000000..4c79cb720eb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitag/model_tagcontractproperties.go @@ -0,0 +1,8 @@ +package apitag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagContractProperties struct { + DisplayName string `json:"displayName"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apitag/predicates.go b/resource-manager/apimanagement/2024-05-01/apitag/predicates.go new file mode 100644 index 00000000000..4123a26d885 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitag/predicates.go @@ -0,0 +1,27 @@ +package apitag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p TagContractOperationPredicate) Matches(input TagContract) 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/apimanagement/2024-05-01/apitag/version.go b/resource-manager/apimanagement/2024-05-01/apitag/version.go new file mode 100644 index 00000000000..e9ff649828e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitag/version.go @@ -0,0 +1,12 @@ +package apitag + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apitag/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apitagdescription/README.md b/resource-manager/apimanagement/2024-05-01/apitagdescription/README.md new file mode 100644 index 00000000000..4a87a3e8ec3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitagdescription/README.md @@ -0,0 +1,106 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apitagdescription` Documentation + +The `apitagdescription` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apitagdescription" +``` + + +### Client Initialization + +```go +client := apitagdescription.NewApiTagDescriptionClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiTagDescriptionClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := apitagdescription.NewTagDescriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "tagDescriptionIdValue") + +payload := apitagdescription.TagDescriptionCreateParameters{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, apitagdescription.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiTagDescriptionClient.Delete` + +```go +ctx := context.TODO() +id := apitagdescription.NewTagDescriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "tagDescriptionIdValue") + +read, err := client.Delete(ctx, id, apitagdescription.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiTagDescriptionClient.Get` + +```go +ctx := context.TODO() +id := apitagdescription.NewTagDescriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "tagDescriptionIdValue") + +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: `ApiTagDescriptionClient.GetEntityTag` + +```go +ctx := context.TODO() +id := apitagdescription.NewTagDescriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "tagDescriptionIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiTagDescriptionClient.ListByService` + +```go +ctx := context.TODO() +id := apitagdescription.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +// alternatively `client.ListByService(ctx, id, apitagdescription.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, apitagdescription.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/apitagdescription/client.go b/resource-manager/apimanagement/2024-05-01/apitagdescription/client.go new file mode 100644 index 00000000000..f3068aee44a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitagdescription/client.go @@ -0,0 +1,26 @@ +package apitagdescription + +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 ApiTagDescriptionClient struct { + Client *resourcemanager.Client +} + +func NewApiTagDescriptionClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiTagDescriptionClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apitagdescription", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiTagDescriptionClient: %+v", err) + } + + return &ApiTagDescriptionClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apitagdescription/id_api.go b/resource-manager/apimanagement/2024-05-01/apitagdescription/id_api.go new file mode 100644 index 00000000000..6c8591fef9e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitagdescription/id_api.go @@ -0,0 +1,139 @@ +package apitagdescription + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiId{}) +} + +var _ resourceids.ResourceId = &ApiId{} + +// ApiId is a struct representing the Resource ID for a Api +type ApiId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string +} + +// NewApiID returns a new ApiId struct +func NewApiID(subscriptionId string, resourceGroupName string, serviceName string, apiId string) ApiId { + return ApiId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + } +} + +// ParseApiID parses 'input' into a ApiId +func ParseApiID(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiIDInsensitively parses 'input' case-insensitively into a ApiId +// note: this method should only be used for API response data and not user input +func ParseApiIDInsensitively(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + return nil +} + +// ValidateApiID checks that 'input' can be parsed as a Api ID +func ValidateApiID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api ID +func (id ApiId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api ID +func (id ApiId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + } +} + +// String returns a human-readable description of this Api ID +func (id ApiId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + } + return fmt.Sprintf("Api (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apitagdescription/id_api_test.go b/resource-manager/apimanagement/2024-05-01/apitagdescription/id_api_test.go new file mode 100644 index 00000000000..018264137c8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitagdescription/id_api_test.go @@ -0,0 +1,327 @@ +package apitagdescription + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiId{} + +func TestNewApiID(t *testing.T) { + id := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } +} + +func TestFormatApiID(t *testing.T) { + actual := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestParseApiIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestSegmentsForApiId(t *testing.T) { + segments := ApiId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apitagdescription/id_tagdescription.go b/resource-manager/apimanagement/2024-05-01/apitagdescription/id_tagdescription.go new file mode 100644 index 00000000000..0e84945f848 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitagdescription/id_tagdescription.go @@ -0,0 +1,148 @@ +package apitagdescription + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TagDescriptionId{}) +} + +var _ resourceids.ResourceId = &TagDescriptionId{} + +// TagDescriptionId is a struct representing the Resource ID for a Tag Description +type TagDescriptionId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string + TagDescriptionId string +} + +// NewTagDescriptionID returns a new TagDescriptionId struct +func NewTagDescriptionID(subscriptionId string, resourceGroupName string, serviceName string, apiId string, tagDescriptionId string) TagDescriptionId { + return TagDescriptionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + TagDescriptionId: tagDescriptionId, + } +} + +// ParseTagDescriptionID parses 'input' into a TagDescriptionId +func ParseTagDescriptionID(input string) (*TagDescriptionId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagDescriptionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagDescriptionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTagDescriptionIDInsensitively parses 'input' case-insensitively into a TagDescriptionId +// note: this method should only be used for API response data and not user input +func ParseTagDescriptionIDInsensitively(input string) (*TagDescriptionId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagDescriptionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagDescriptionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TagDescriptionId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + if id.TagDescriptionId, ok = input.Parsed["tagDescriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagDescriptionId", input) + } + + return nil +} + +// ValidateTagDescriptionID checks that 'input' can be parsed as a Tag Description ID +func ValidateTagDescriptionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseTagDescriptionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Tag Description ID +func (id TagDescriptionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s/tagDescriptions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId, id.TagDescriptionId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Tag Description ID +func (id TagDescriptionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + resourceids.StaticSegment("staticTagDescriptions", "tagDescriptions", "tagDescriptions"), + resourceids.UserSpecifiedSegment("tagDescriptionId", "tagDescriptionIdValue"), + } +} + +// String returns a human-readable description of this Tag Description ID +func (id TagDescriptionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + fmt.Sprintf("Tag Description: %q", id.TagDescriptionId), + } + return fmt.Sprintf("Tag Description (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apitagdescription/id_tagdescription_test.go b/resource-manager/apimanagement/2024-05-01/apitagdescription/id_tagdescription_test.go new file mode 100644 index 00000000000..0f11b786815 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitagdescription/id_tagdescription_test.go @@ -0,0 +1,372 @@ +package apitagdescription + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TagDescriptionId{} + +func TestNewTagDescriptionID(t *testing.T) { + id := NewTagDescriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "tagDescriptionIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } + + if id.TagDescriptionId != "tagDescriptionIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'TagDescriptionId'", id.TagDescriptionId, "tagDescriptionIdValue") + } +} + +func TestFormatTagDescriptionID(t *testing.T) { + actual := NewTagDescriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "tagDescriptionIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/tagDescriptions/tagDescriptionIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTagDescriptionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagDescriptionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/tagDescriptions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/tagDescriptions/tagDescriptionIdValue", + Expected: &TagDescriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + TagDescriptionId: "tagDescriptionIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/tagDescriptions/tagDescriptionIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagDescriptionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.TagDescriptionId != v.Expected.TagDescriptionId { + t.Fatalf("Expected %q but got %q for TagDescriptionId", v.Expected.TagDescriptionId, actual.TagDescriptionId) + } + + } +} + +func TestParseTagDescriptionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagDescriptionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/tagDescriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/tAgDeScRiPtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/tagDescriptions/tagDescriptionIdValue", + Expected: &TagDescriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + TagDescriptionId: "tagDescriptionIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/tagDescriptions/tagDescriptionIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/tAgDeScRiPtIoNs/tAgDeScRiPtIoNiDvAlUe", + Expected: &TagDescriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + TagDescriptionId: "tAgDeScRiPtIoNiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/tAgDeScRiPtIoNs/tAgDeScRiPtIoNiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagDescriptionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.TagDescriptionId != v.Expected.TagDescriptionId { + t.Fatalf("Expected %q but got %q for TagDescriptionId", v.Expected.TagDescriptionId, actual.TagDescriptionId) + } + + } +} + +func TestSegmentsForTagDescriptionId(t *testing.T) { + segments := TagDescriptionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TagDescriptionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apitagdescription/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/apitagdescription/method_createorupdate.go new file mode 100644 index 00000000000..11d74115f05 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitagdescription/method_createorupdate.go @@ -0,0 +1,88 @@ +package apitagdescription + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TagDescriptionContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c ApiTagDescriptionClient) CreateOrUpdate(ctx context.Context, id TagDescriptionId, input TagDescriptionCreateParameters, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 TagDescriptionContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apitagdescription/method_delete.go b/resource-manager/apimanagement/2024-05-01/apitagdescription/method_delete.go new file mode 100644 index 00000000000..2ac6057d339 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitagdescription/method_delete.go @@ -0,0 +1,76 @@ +package apitagdescription + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c ApiTagDescriptionClient) Delete(ctx context.Context, id TagDescriptionId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apitagdescription/method_get.go b/resource-manager/apimanagement/2024-05-01/apitagdescription/method_get.go new file mode 100644 index 00000000000..e350b63f26f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitagdescription/method_get.go @@ -0,0 +1,54 @@ +package apitagdescription + +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 *TagDescriptionContract +} + +// Get ... +func (c ApiTagDescriptionClient) Get(ctx context.Context, id TagDescriptionId) (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 TagDescriptionContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apitagdescription/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/apitagdescription/method_getentitytag.go new file mode 100644 index 00000000000..1db8e6e13d4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitagdescription/method_getentitytag.go @@ -0,0 +1,46 @@ +package apitagdescription + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c ApiTagDescriptionClient) GetEntityTag(ctx context.Context, id TagDescriptionId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apitagdescription/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/apitagdescription/method_listbyservice.go new file mode 100644 index 00000000000..6a36cd97456 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitagdescription/method_listbyservice.go @@ -0,0 +1,141 @@ +package apitagdescription + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TagDescriptionContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []TagDescriptionContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c ApiTagDescriptionClient) ListByService(ctx context.Context, id ApiId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/tagDescriptions", 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 *[]TagDescriptionContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c ApiTagDescriptionClient) ListByServiceComplete(ctx context.Context, id ApiId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, TagDescriptionContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiTagDescriptionClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ApiId, options ListByServiceOperationOptions, predicate TagDescriptionContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]TagDescriptionContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apitagdescription/model_tagdescriptionbaseproperties.go b/resource-manager/apimanagement/2024-05-01/apitagdescription/model_tagdescriptionbaseproperties.go new file mode 100644 index 00000000000..cb5c534f1af --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitagdescription/model_tagdescriptionbaseproperties.go @@ -0,0 +1,10 @@ +package apitagdescription + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagDescriptionBaseProperties struct { + Description *string `json:"description,omitempty"` + ExternalDocsDescription *string `json:"externalDocsDescription,omitempty"` + ExternalDocsUrl *string `json:"externalDocsUrl,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apitagdescription/model_tagdescriptioncontract.go b/resource-manager/apimanagement/2024-05-01/apitagdescription/model_tagdescriptioncontract.go new file mode 100644 index 00000000000..c18f3539075 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitagdescription/model_tagdescriptioncontract.go @@ -0,0 +1,11 @@ +package apitagdescription + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagDescriptionContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *TagDescriptionContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apitagdescription/model_tagdescriptioncontractproperties.go b/resource-manager/apimanagement/2024-05-01/apitagdescription/model_tagdescriptioncontractproperties.go new file mode 100644 index 00000000000..071eefae7d3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitagdescription/model_tagdescriptioncontractproperties.go @@ -0,0 +1,12 @@ +package apitagdescription + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagDescriptionContractProperties struct { + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + ExternalDocsDescription *string `json:"externalDocsDescription,omitempty"` + ExternalDocsUrl *string `json:"externalDocsUrl,omitempty"` + TagId *string `json:"tagId,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apitagdescription/model_tagdescriptioncreateparameters.go b/resource-manager/apimanagement/2024-05-01/apitagdescription/model_tagdescriptioncreateparameters.go new file mode 100644 index 00000000000..405c7b46c9c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitagdescription/model_tagdescriptioncreateparameters.go @@ -0,0 +1,8 @@ +package apitagdescription + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagDescriptionCreateParameters struct { + Properties *TagDescriptionBaseProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apitagdescription/predicates.go b/resource-manager/apimanagement/2024-05-01/apitagdescription/predicates.go new file mode 100644 index 00000000000..e42faf26df9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitagdescription/predicates.go @@ -0,0 +1,27 @@ +package apitagdescription + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagDescriptionContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p TagDescriptionContractOperationPredicate) Matches(input TagDescriptionContract) 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/apimanagement/2024-05-01/apitagdescription/version.go b/resource-manager/apimanagement/2024-05-01/apitagdescription/version.go new file mode 100644 index 00000000000..42468751cf4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apitagdescription/version.go @@ -0,0 +1,12 @@ +package apitagdescription + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apitagdescription/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/README.md b/resource-manager/apimanagement/2024-05-01/apiversionset/README.md new file mode 100644 index 00000000000..2bc413796be --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/README.md @@ -0,0 +1,202 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apiversionset` Documentation + +The `apiversionset` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apiversionset" +``` + + +### Client Initialization + +```go +client := apiversionset.NewApiVersionSetClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiVersionSetClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := apiversionset.NewApiVersionSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "versionSetIdValue") + +payload := apiversionset.ApiVersionSetContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, apiversionset.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiVersionSetClient.Get` + +```go +ctx := context.TODO() +id := apiversionset.NewApiVersionSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "versionSetIdValue") + +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: `ApiVersionSetClient.GetEntityTag` + +```go +ctx := context.TODO() +id := apiversionset.NewApiVersionSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "versionSetIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiVersionSetClient.ListByService` + +```go +ctx := context.TODO() +id := apiversionset.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, apiversionset.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, apiversionset.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ApiVersionSetClient.Update` + +```go +ctx := context.TODO() +id := apiversionset.NewApiVersionSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "versionSetIdValue") + +payload := apiversionset.ApiVersionSetUpdateParameters{ + // ... +} + + +read, err := client.Update(ctx, id, payload, apiversionset.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiVersionSetClient.WorkspaceApiVersionSetCreateOrUpdate` + +```go +ctx := context.TODO() +id := apiversionset.NewWorkspaceApiVersionSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "versionSetIdValue") + +payload := apiversionset.ApiVersionSetContract{ + // ... +} + + +read, err := client.WorkspaceApiVersionSetCreateOrUpdate(ctx, id, payload, apiversionset.DefaultWorkspaceApiVersionSetCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiVersionSetClient.WorkspaceApiVersionSetGet` + +```go +ctx := context.TODO() +id := apiversionset.NewWorkspaceApiVersionSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "versionSetIdValue") + +read, err := client.WorkspaceApiVersionSetGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiVersionSetClient.WorkspaceApiVersionSetGetEntityTag` + +```go +ctx := context.TODO() +id := apiversionset.NewWorkspaceApiVersionSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "versionSetIdValue") + +read, err := client.WorkspaceApiVersionSetGetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiVersionSetClient.WorkspaceApiVersionSetListByService` + +```go +ctx := context.TODO() +id := apiversionset.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +// alternatively `client.WorkspaceApiVersionSetListByService(ctx, id, apiversionset.DefaultWorkspaceApiVersionSetListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.WorkspaceApiVersionSetListByServiceComplete(ctx, id, apiversionset.DefaultWorkspaceApiVersionSetListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ApiVersionSetClient.WorkspaceApiVersionSetUpdate` + +```go +ctx := context.TODO() +id := apiversionset.NewWorkspaceApiVersionSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "versionSetIdValue") + +payload := apiversionset.ApiVersionSetUpdateParameters{ + // ... +} + + +read, err := client.WorkspaceApiVersionSetUpdate(ctx, id, payload, apiversionset.DefaultWorkspaceApiVersionSetUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/client.go b/resource-manager/apimanagement/2024-05-01/apiversionset/client.go new file mode 100644 index 00000000000..ff0c4d18fb0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/client.go @@ -0,0 +1,26 @@ +package apiversionset + +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 ApiVersionSetClient struct { + Client *resourcemanager.Client +} + +func NewApiVersionSetClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiVersionSetClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apiversionset", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiVersionSetClient: %+v", err) + } + + return &ApiVersionSetClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/constants.go b/resource-manager/apimanagement/2024-05-01/apiversionset/constants.go new file mode 100644 index 00000000000..4fb4d169fff --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/constants.go @@ -0,0 +1,54 @@ +package apiversionset + +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 VersioningScheme string + +const ( + VersioningSchemeHeader VersioningScheme = "Header" + VersioningSchemeQuery VersioningScheme = "Query" + VersioningSchemeSegment VersioningScheme = "Segment" +) + +func PossibleValuesForVersioningScheme() []string { + return []string{ + string(VersioningSchemeHeader), + string(VersioningSchemeQuery), + string(VersioningSchemeSegment), + } +} + +func (s *VersioningScheme) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVersioningScheme(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVersioningScheme(input string) (*VersioningScheme, error) { + vals := map[string]VersioningScheme{ + "header": VersioningSchemeHeader, + "query": VersioningSchemeQuery, + "segment": VersioningSchemeSegment, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VersioningScheme(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/id_apiversionset.go b/resource-manager/apimanagement/2024-05-01/apiversionset/id_apiversionset.go new file mode 100644 index 00000000000..6a1476b429c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/id_apiversionset.go @@ -0,0 +1,139 @@ +package apiversionset + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiVersionSetId{}) +} + +var _ resourceids.ResourceId = &ApiVersionSetId{} + +// ApiVersionSetId is a struct representing the Resource ID for a Api Version Set +type ApiVersionSetId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + VersionSetId string +} + +// NewApiVersionSetID returns a new ApiVersionSetId struct +func NewApiVersionSetID(subscriptionId string, resourceGroupName string, serviceName string, versionSetId string) ApiVersionSetId { + return ApiVersionSetId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + VersionSetId: versionSetId, + } +} + +// ParseApiVersionSetID parses 'input' into a ApiVersionSetId +func ParseApiVersionSetID(input string) (*ApiVersionSetId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiVersionSetId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiVersionSetId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiVersionSetIDInsensitively parses 'input' case-insensitively into a ApiVersionSetId +// note: this method should only be used for API response data and not user input +func ParseApiVersionSetIDInsensitively(input string) (*ApiVersionSetId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiVersionSetId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiVersionSetId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiVersionSetId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.VersionSetId, ok = input.Parsed["versionSetId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "versionSetId", input) + } + + return nil +} + +// ValidateApiVersionSetID checks that 'input' can be parsed as a Api Version Set ID +func ValidateApiVersionSetID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiVersionSetID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api Version Set ID +func (id ApiVersionSetId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apiVersionSets/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.VersionSetId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api Version Set ID +func (id ApiVersionSetId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApiVersionSets", "apiVersionSets", "apiVersionSets"), + resourceids.UserSpecifiedSegment("versionSetId", "versionSetIdValue"), + } +} + +// String returns a human-readable description of this Api Version Set ID +func (id ApiVersionSetId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Version Set: %q", id.VersionSetId), + } + return fmt.Sprintf("Api Version Set (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/id_apiversionset_test.go b/resource-manager/apimanagement/2024-05-01/apiversionset/id_apiversionset_test.go new file mode 100644 index 00000000000..084b145852d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/id_apiversionset_test.go @@ -0,0 +1,327 @@ +package apiversionset + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiVersionSetId{} + +func TestNewApiVersionSetID(t *testing.T) { + id := NewApiVersionSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "versionSetIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.VersionSetId != "versionSetIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'VersionSetId'", id.VersionSetId, "versionSetIdValue") + } +} + +func TestFormatApiVersionSetID(t *testing.T) { + actual := NewApiVersionSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "versionSetIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apiVersionSets/versionSetIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiVersionSetID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiVersionSetId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apiVersionSets", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apiVersionSets/versionSetIdValue", + Expected: &ApiVersionSetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + VersionSetId: "versionSetIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apiVersionSets/versionSetIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiVersionSetID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.VersionSetId != v.Expected.VersionSetId { + t.Fatalf("Expected %q but got %q for VersionSetId", v.Expected.VersionSetId, actual.VersionSetId) + } + + } +} + +func TestParseApiVersionSetIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiVersionSetId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apiVersionSets", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiVeRsIoNsEtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apiVersionSets/versionSetIdValue", + Expected: &ApiVersionSetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + VersionSetId: "versionSetIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apiVersionSets/versionSetIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiVeRsIoNsEtS/vErSiOnSeTiDvAlUe", + Expected: &ApiVersionSetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + VersionSetId: "vErSiOnSeTiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiVeRsIoNsEtS/vErSiOnSeTiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiVersionSetIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.VersionSetId != v.Expected.VersionSetId { + t.Fatalf("Expected %q but got %q for VersionSetId", v.Expected.VersionSetId, actual.VersionSetId) + } + + } +} + +func TestSegmentsForApiVersionSetId(t *testing.T) { + segments := ApiVersionSetId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiVersionSetId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/id_service.go b/resource-manager/apimanagement/2024-05-01/apiversionset/id_service.go new file mode 100644 index 00000000000..fe44a488d70 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/id_service.go @@ -0,0 +1,130 @@ +package apiversionset + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/id_service_test.go b/resource-manager/apimanagement/2024-05-01/apiversionset/id_service_test.go new file mode 100644 index 00000000000..6388f19ed1c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/id_service_test.go @@ -0,0 +1,282 @@ +package apiversionset + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/id_workspace.go b/resource-manager/apimanagement/2024-05-01/apiversionset/id_workspace.go new file mode 100644 index 00000000000..ffae2571e19 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/id_workspace.go @@ -0,0 +1,139 @@ +package apiversionset + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/id_workspace_test.go b/resource-manager/apimanagement/2024-05-01/apiversionset/id_workspace_test.go new file mode 100644 index 00000000000..82f138453a1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/id_workspace_test.go @@ -0,0 +1,327 @@ +package apiversionset + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/id_workspaceapiversionset.go b/resource-manager/apimanagement/2024-05-01/apiversionset/id_workspaceapiversionset.go new file mode 100644 index 00000000000..07c056e413c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/id_workspaceapiversionset.go @@ -0,0 +1,148 @@ +package apiversionset + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceApiVersionSetId{}) +} + +var _ resourceids.ResourceId = &WorkspaceApiVersionSetId{} + +// WorkspaceApiVersionSetId is a struct representing the Resource ID for a Workspace Api Version Set +type WorkspaceApiVersionSetId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + VersionSetId string +} + +// NewWorkspaceApiVersionSetID returns a new WorkspaceApiVersionSetId struct +func NewWorkspaceApiVersionSetID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, versionSetId string) WorkspaceApiVersionSetId { + return WorkspaceApiVersionSetId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + VersionSetId: versionSetId, + } +} + +// ParseWorkspaceApiVersionSetID parses 'input' into a WorkspaceApiVersionSetId +func ParseWorkspaceApiVersionSetID(input string) (*WorkspaceApiVersionSetId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceApiVersionSetId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceApiVersionSetId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceApiVersionSetIDInsensitively parses 'input' case-insensitively into a WorkspaceApiVersionSetId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceApiVersionSetIDInsensitively(input string) (*WorkspaceApiVersionSetId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceApiVersionSetId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceApiVersionSetId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceApiVersionSetId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.VersionSetId, ok = input.Parsed["versionSetId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "versionSetId", input) + } + + return nil +} + +// ValidateWorkspaceApiVersionSetID checks that 'input' can be parsed as a Workspace Api Version Set ID +func ValidateWorkspaceApiVersionSetID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceApiVersionSetID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Api Version Set ID +func (id WorkspaceApiVersionSetId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/apiVersionSets/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.VersionSetId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Api Version Set ID +func (id WorkspaceApiVersionSetId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticApiVersionSets", "apiVersionSets", "apiVersionSets"), + resourceids.UserSpecifiedSegment("versionSetId", "versionSetIdValue"), + } +} + +// String returns a human-readable description of this Workspace Api Version Set ID +func (id WorkspaceApiVersionSetId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Version Set: %q", id.VersionSetId), + } + return fmt.Sprintf("Workspace Api Version Set (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/id_workspaceapiversionset_test.go b/resource-manager/apimanagement/2024-05-01/apiversionset/id_workspaceapiversionset_test.go new file mode 100644 index 00000000000..d88e8d0f779 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/id_workspaceapiversionset_test.go @@ -0,0 +1,372 @@ +package apiversionset + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceApiVersionSetId{} + +func TestNewWorkspaceApiVersionSetID(t *testing.T) { + id := NewWorkspaceApiVersionSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "versionSetIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.VersionSetId != "versionSetIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'VersionSetId'", id.VersionSetId, "versionSetIdValue") + } +} + +func TestFormatWorkspaceApiVersionSetID(t *testing.T) { + actual := NewWorkspaceApiVersionSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "versionSetIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apiVersionSets/versionSetIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceApiVersionSetID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceApiVersionSetId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apiVersionSets", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apiVersionSets/versionSetIdValue", + Expected: &WorkspaceApiVersionSetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + VersionSetId: "versionSetIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apiVersionSets/versionSetIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceApiVersionSetID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.VersionSetId != v.Expected.VersionSetId { + t.Fatalf("Expected %q but got %q for VersionSetId", v.Expected.VersionSetId, actual.VersionSetId) + } + + } +} + +func TestParseWorkspaceApiVersionSetIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceApiVersionSetId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apiVersionSets", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiVeRsIoNsEtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apiVersionSets/versionSetIdValue", + Expected: &WorkspaceApiVersionSetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + VersionSetId: "versionSetIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apiVersionSets/versionSetIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiVeRsIoNsEtS/vErSiOnSeTiDvAlUe", + Expected: &WorkspaceApiVersionSetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + VersionSetId: "vErSiOnSeTiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiVeRsIoNsEtS/vErSiOnSeTiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceApiVersionSetIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.VersionSetId != v.Expected.VersionSetId { + t.Fatalf("Expected %q but got %q for VersionSetId", v.Expected.VersionSetId, actual.VersionSetId) + } + + } +} + +func TestSegmentsForWorkspaceApiVersionSetId(t *testing.T) { + segments := WorkspaceApiVersionSetId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceApiVersionSetId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/apiversionset/method_createorupdate.go new file mode 100644 index 00000000000..2d070fcbf91 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/method_createorupdate.go @@ -0,0 +1,88 @@ +package apiversionset + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ApiVersionSetContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c ApiVersionSetClient) CreateOrUpdate(ctx context.Context, id ApiVersionSetId, input ApiVersionSetContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 ApiVersionSetContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/method_get.go b/resource-manager/apimanagement/2024-05-01/apiversionset/method_get.go new file mode 100644 index 00000000000..7b7c728908e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/method_get.go @@ -0,0 +1,54 @@ +package apiversionset + +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 *ApiVersionSetContract +} + +// Get ... +func (c ApiVersionSetClient) Get(ctx context.Context, id ApiVersionSetId) (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 ApiVersionSetContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/apiversionset/method_getentitytag.go new file mode 100644 index 00000000000..9f95f1e557c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/method_getentitytag.go @@ -0,0 +1,46 @@ +package apiversionset + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c ApiVersionSetClient) GetEntityTag(ctx context.Context, id ApiVersionSetId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/apiversionset/method_listbyservice.go new file mode 100644 index 00000000000..0f44e4d938d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/method_listbyservice.go @@ -0,0 +1,141 @@ +package apiversionset + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ApiVersionSetContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ApiVersionSetContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c ApiVersionSetClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/apiVersionSets", 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 *[]ApiVersionSetContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c ApiVersionSetClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, ApiVersionSetContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiVersionSetClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate ApiVersionSetContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]ApiVersionSetContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/method_update.go b/resource-manager/apimanagement/2024-05-01/apiversionset/method_update.go new file mode 100644 index 00000000000..97fce9046f6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/method_update.go @@ -0,0 +1,87 @@ +package apiversionset + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ApiVersionSetContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c ApiVersionSetClient) Update(ctx context.Context, id ApiVersionSetId, input ApiVersionSetUpdateParameters, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 ApiVersionSetContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/method_workspaceapiversionsetcreateorupdate.go b/resource-manager/apimanagement/2024-05-01/apiversionset/method_workspaceapiversionsetcreateorupdate.go new file mode 100644 index 00000000000..0fde6db7b9f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/method_workspaceapiversionsetcreateorupdate.go @@ -0,0 +1,88 @@ +package apiversionset + +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 WorkspaceApiVersionSetCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ApiVersionSetContract +} + +type WorkspaceApiVersionSetCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceApiVersionSetCreateOrUpdateOperationOptions() WorkspaceApiVersionSetCreateOrUpdateOperationOptions { + return WorkspaceApiVersionSetCreateOrUpdateOperationOptions{} +} + +func (o WorkspaceApiVersionSetCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceApiVersionSetCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiVersionSetCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceApiVersionSetCreateOrUpdate ... +func (c ApiVersionSetClient) WorkspaceApiVersionSetCreateOrUpdate(ctx context.Context, id WorkspaceApiVersionSetId, input ApiVersionSetContract, options WorkspaceApiVersionSetCreateOrUpdateOperationOptions) (result WorkspaceApiVersionSetCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 ApiVersionSetContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/method_workspaceapiversionsetget.go b/resource-manager/apimanagement/2024-05-01/apiversionset/method_workspaceapiversionsetget.go new file mode 100644 index 00000000000..2a61095ca42 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/method_workspaceapiversionsetget.go @@ -0,0 +1,54 @@ +package apiversionset + +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 WorkspaceApiVersionSetGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ApiVersionSetContract +} + +// WorkspaceApiVersionSetGet ... +func (c ApiVersionSetClient) WorkspaceApiVersionSetGet(ctx context.Context, id WorkspaceApiVersionSetId) (result WorkspaceApiVersionSetGetOperationResponse, 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 ApiVersionSetContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/method_workspaceapiversionsetgetentitytag.go b/resource-manager/apimanagement/2024-05-01/apiversionset/method_workspaceapiversionsetgetentitytag.go new file mode 100644 index 00000000000..f5215e18478 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/method_workspaceapiversionsetgetentitytag.go @@ -0,0 +1,46 @@ +package apiversionset + +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 WorkspaceApiVersionSetGetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceApiVersionSetGetEntityTag ... +func (c ApiVersionSetClient) WorkspaceApiVersionSetGetEntityTag(ctx context.Context, id WorkspaceApiVersionSetId) (result WorkspaceApiVersionSetGetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/method_workspaceapiversionsetlistbyservice.go b/resource-manager/apimanagement/2024-05-01/apiversionset/method_workspaceapiversionsetlistbyservice.go new file mode 100644 index 00000000000..e65dc1b5956 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/method_workspaceapiversionsetlistbyservice.go @@ -0,0 +1,141 @@ +package apiversionset + +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 WorkspaceApiVersionSetListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ApiVersionSetContract +} + +type WorkspaceApiVersionSetListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ApiVersionSetContract +} + +type WorkspaceApiVersionSetListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultWorkspaceApiVersionSetListByServiceOperationOptions() WorkspaceApiVersionSetListByServiceOperationOptions { + return WorkspaceApiVersionSetListByServiceOperationOptions{} +} + +func (o WorkspaceApiVersionSetListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceApiVersionSetListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiVersionSetListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspaceApiVersionSetListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceApiVersionSetListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceApiVersionSetListByService ... +func (c ApiVersionSetClient) WorkspaceApiVersionSetListByService(ctx context.Context, id WorkspaceId, options WorkspaceApiVersionSetListByServiceOperationOptions) (result WorkspaceApiVersionSetListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspaceApiVersionSetListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/apiVersionSets", 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 *[]ApiVersionSetContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceApiVersionSetListByServiceComplete retrieves all the results into a single object +func (c ApiVersionSetClient) WorkspaceApiVersionSetListByServiceComplete(ctx context.Context, id WorkspaceId, options WorkspaceApiVersionSetListByServiceOperationOptions) (WorkspaceApiVersionSetListByServiceCompleteResult, error) { + return c.WorkspaceApiVersionSetListByServiceCompleteMatchingPredicate(ctx, id, options, ApiVersionSetContractOperationPredicate{}) +} + +// WorkspaceApiVersionSetListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiVersionSetClient) WorkspaceApiVersionSetListByServiceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options WorkspaceApiVersionSetListByServiceOperationOptions, predicate ApiVersionSetContractOperationPredicate) (result WorkspaceApiVersionSetListByServiceCompleteResult, err error) { + items := make([]ApiVersionSetContract, 0) + + resp, err := c.WorkspaceApiVersionSetListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceApiVersionSetListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/method_workspaceapiversionsetupdate.go b/resource-manager/apimanagement/2024-05-01/apiversionset/method_workspaceapiversionsetupdate.go new file mode 100644 index 00000000000..dda3ecdb80b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/method_workspaceapiversionsetupdate.go @@ -0,0 +1,87 @@ +package apiversionset + +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 WorkspaceApiVersionSetUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ApiVersionSetContract +} + +type WorkspaceApiVersionSetUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceApiVersionSetUpdateOperationOptions() WorkspaceApiVersionSetUpdateOperationOptions { + return WorkspaceApiVersionSetUpdateOperationOptions{} +} + +func (o WorkspaceApiVersionSetUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceApiVersionSetUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiVersionSetUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceApiVersionSetUpdate ... +func (c ApiVersionSetClient) WorkspaceApiVersionSetUpdate(ctx context.Context, id WorkspaceApiVersionSetId, input ApiVersionSetUpdateParameters, options WorkspaceApiVersionSetUpdateOperationOptions) (result WorkspaceApiVersionSetUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 ApiVersionSetContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/model_apiversionsetcontract.go b/resource-manager/apimanagement/2024-05-01/apiversionset/model_apiversionsetcontract.go new file mode 100644 index 00000000000..8fdb4cc3e1a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/model_apiversionsetcontract.go @@ -0,0 +1,11 @@ +package apiversionset + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiVersionSetContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ApiVersionSetContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/model_apiversionsetcontractproperties.go b/resource-manager/apimanagement/2024-05-01/apiversionset/model_apiversionsetcontractproperties.go new file mode 100644 index 00000000000..9130fed751c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/model_apiversionsetcontractproperties.go @@ -0,0 +1,12 @@ +package apiversionset + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiVersionSetContractProperties struct { + Description *string `json:"description,omitempty"` + DisplayName string `json:"displayName"` + VersionHeaderName *string `json:"versionHeaderName,omitempty"` + VersionQueryName *string `json:"versionQueryName,omitempty"` + VersioningScheme VersioningScheme `json:"versioningScheme"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/model_apiversionsetupdateparameters.go b/resource-manager/apimanagement/2024-05-01/apiversionset/model_apiversionsetupdateparameters.go new file mode 100644 index 00000000000..4cafb4be098 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/model_apiversionsetupdateparameters.go @@ -0,0 +1,8 @@ +package apiversionset + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiVersionSetUpdateParameters struct { + Properties *ApiVersionSetUpdateParametersProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/model_apiversionsetupdateparametersproperties.go b/resource-manager/apimanagement/2024-05-01/apiversionset/model_apiversionsetupdateparametersproperties.go new file mode 100644 index 00000000000..733e18195de --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/model_apiversionsetupdateparametersproperties.go @@ -0,0 +1,12 @@ +package apiversionset + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiVersionSetUpdateParametersProperties struct { + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + VersionHeaderName *string `json:"versionHeaderName,omitempty"` + VersionQueryName *string `json:"versionQueryName,omitempty"` + VersioningScheme *VersioningScheme `json:"versioningScheme,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionset/predicates.go b/resource-manager/apimanagement/2024-05-01/apiversionset/predicates.go new file mode 100644 index 00000000000..66a673e544d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/predicates.go @@ -0,0 +1,27 @@ +package apiversionset + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiVersionSetContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ApiVersionSetContractOperationPredicate) Matches(input ApiVersionSetContract) 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/apimanagement/2024-05-01/apiversionset/version.go b/resource-manager/apimanagement/2024-05-01/apiversionset/version.go new file mode 100644 index 00000000000..1a1f53494ed --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionset/version.go @@ -0,0 +1,12 @@ +package apiversionset + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apiversionset/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionsets/client.go b/resource-manager/apimanagement/2024-05-01/apiversionsets/client.go new file mode 100644 index 00000000000..e1665dd8077 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionsets/client.go @@ -0,0 +1,26 @@ +package apiversionsets + +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 ApiVersionSetsClient struct { + Client *resourcemanager.Client +} + +func NewApiVersionSetsClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiVersionSetsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apiversionsets", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiVersionSetsClient: %+v", err) + } + + return &ApiVersionSetsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionsets/id_apiversionset.go b/resource-manager/apimanagement/2024-05-01/apiversionsets/id_apiversionset.go new file mode 100644 index 00000000000..ef4fd9b314b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionsets/id_apiversionset.go @@ -0,0 +1,139 @@ +package apiversionsets + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiVersionSetId{}) +} + +var _ resourceids.ResourceId = &ApiVersionSetId{} + +// ApiVersionSetId is a struct representing the Resource ID for a Api Version Set +type ApiVersionSetId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + VersionSetId string +} + +// NewApiVersionSetID returns a new ApiVersionSetId struct +func NewApiVersionSetID(subscriptionId string, resourceGroupName string, serviceName string, versionSetId string) ApiVersionSetId { + return ApiVersionSetId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + VersionSetId: versionSetId, + } +} + +// ParseApiVersionSetID parses 'input' into a ApiVersionSetId +func ParseApiVersionSetID(input string) (*ApiVersionSetId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiVersionSetId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiVersionSetId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiVersionSetIDInsensitively parses 'input' case-insensitively into a ApiVersionSetId +// note: this method should only be used for API response data and not user input +func ParseApiVersionSetIDInsensitively(input string) (*ApiVersionSetId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiVersionSetId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiVersionSetId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiVersionSetId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.VersionSetId, ok = input.Parsed["versionSetId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "versionSetId", input) + } + + return nil +} + +// ValidateApiVersionSetID checks that 'input' can be parsed as a Api Version Set ID +func ValidateApiVersionSetID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiVersionSetID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api Version Set ID +func (id ApiVersionSetId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apiVersionSets/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.VersionSetId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api Version Set ID +func (id ApiVersionSetId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApiVersionSets", "apiVersionSets", "apiVersionSets"), + resourceids.UserSpecifiedSegment("versionSetId", "versionSetIdValue"), + } +} + +// String returns a human-readable description of this Api Version Set ID +func (id ApiVersionSetId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Version Set: %q", id.VersionSetId), + } + return fmt.Sprintf("Api Version Set (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionsets/id_apiversionset_test.go b/resource-manager/apimanagement/2024-05-01/apiversionsets/id_apiversionset_test.go new file mode 100644 index 00000000000..93e2115edb4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionsets/id_apiversionset_test.go @@ -0,0 +1,327 @@ +package apiversionsets + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiVersionSetId{} + +func TestNewApiVersionSetID(t *testing.T) { + id := NewApiVersionSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "versionSetIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.VersionSetId != "versionSetIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'VersionSetId'", id.VersionSetId, "versionSetIdValue") + } +} + +func TestFormatApiVersionSetID(t *testing.T) { + actual := NewApiVersionSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "versionSetIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apiVersionSets/versionSetIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiVersionSetID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiVersionSetId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apiVersionSets", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apiVersionSets/versionSetIdValue", + Expected: &ApiVersionSetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + VersionSetId: "versionSetIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apiVersionSets/versionSetIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiVersionSetID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.VersionSetId != v.Expected.VersionSetId { + t.Fatalf("Expected %q but got %q for VersionSetId", v.Expected.VersionSetId, actual.VersionSetId) + } + + } +} + +func TestParseApiVersionSetIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiVersionSetId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apiVersionSets", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiVeRsIoNsEtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apiVersionSets/versionSetIdValue", + Expected: &ApiVersionSetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + VersionSetId: "versionSetIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apiVersionSets/versionSetIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiVeRsIoNsEtS/vErSiOnSeTiDvAlUe", + Expected: &ApiVersionSetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + VersionSetId: "vErSiOnSeTiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiVeRsIoNsEtS/vErSiOnSeTiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiVersionSetIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.VersionSetId != v.Expected.VersionSetId { + t.Fatalf("Expected %q but got %q for VersionSetId", v.Expected.VersionSetId, actual.VersionSetId) + } + + } +} + +func TestSegmentsForApiVersionSetId(t *testing.T) { + segments := ApiVersionSetId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiVersionSetId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionsets/id_workspaceapiversionset.go b/resource-manager/apimanagement/2024-05-01/apiversionsets/id_workspaceapiversionset.go new file mode 100644 index 00000000000..c5271af64dc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionsets/id_workspaceapiversionset.go @@ -0,0 +1,148 @@ +package apiversionsets + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceApiVersionSetId{}) +} + +var _ resourceids.ResourceId = &WorkspaceApiVersionSetId{} + +// WorkspaceApiVersionSetId is a struct representing the Resource ID for a Workspace Api Version Set +type WorkspaceApiVersionSetId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + VersionSetId string +} + +// NewWorkspaceApiVersionSetID returns a new WorkspaceApiVersionSetId struct +func NewWorkspaceApiVersionSetID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, versionSetId string) WorkspaceApiVersionSetId { + return WorkspaceApiVersionSetId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + VersionSetId: versionSetId, + } +} + +// ParseWorkspaceApiVersionSetID parses 'input' into a WorkspaceApiVersionSetId +func ParseWorkspaceApiVersionSetID(input string) (*WorkspaceApiVersionSetId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceApiVersionSetId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceApiVersionSetId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceApiVersionSetIDInsensitively parses 'input' case-insensitively into a WorkspaceApiVersionSetId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceApiVersionSetIDInsensitively(input string) (*WorkspaceApiVersionSetId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceApiVersionSetId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceApiVersionSetId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceApiVersionSetId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.VersionSetId, ok = input.Parsed["versionSetId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "versionSetId", input) + } + + return nil +} + +// ValidateWorkspaceApiVersionSetID checks that 'input' can be parsed as a Workspace Api Version Set ID +func ValidateWorkspaceApiVersionSetID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceApiVersionSetID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Api Version Set ID +func (id WorkspaceApiVersionSetId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/apiVersionSets/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.VersionSetId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Api Version Set ID +func (id WorkspaceApiVersionSetId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticApiVersionSets", "apiVersionSets", "apiVersionSets"), + resourceids.UserSpecifiedSegment("versionSetId", "versionSetIdValue"), + } +} + +// String returns a human-readable description of this Workspace Api Version Set ID +func (id WorkspaceApiVersionSetId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Version Set: %q", id.VersionSetId), + } + return fmt.Sprintf("Workspace Api Version Set (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionsets/id_workspaceapiversionset_test.go b/resource-manager/apimanagement/2024-05-01/apiversionsets/id_workspaceapiversionset_test.go new file mode 100644 index 00000000000..98daf7a6de0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionsets/id_workspaceapiversionset_test.go @@ -0,0 +1,372 @@ +package apiversionsets + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceApiVersionSetId{} + +func TestNewWorkspaceApiVersionSetID(t *testing.T) { + id := NewWorkspaceApiVersionSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "versionSetIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.VersionSetId != "versionSetIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'VersionSetId'", id.VersionSetId, "versionSetIdValue") + } +} + +func TestFormatWorkspaceApiVersionSetID(t *testing.T) { + actual := NewWorkspaceApiVersionSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "versionSetIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apiVersionSets/versionSetIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceApiVersionSetID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceApiVersionSetId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apiVersionSets", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apiVersionSets/versionSetIdValue", + Expected: &WorkspaceApiVersionSetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + VersionSetId: "versionSetIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apiVersionSets/versionSetIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceApiVersionSetID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.VersionSetId != v.Expected.VersionSetId { + t.Fatalf("Expected %q but got %q for VersionSetId", v.Expected.VersionSetId, actual.VersionSetId) + } + + } +} + +func TestParseWorkspaceApiVersionSetIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceApiVersionSetId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apiVersionSets", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiVeRsIoNsEtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apiVersionSets/versionSetIdValue", + Expected: &WorkspaceApiVersionSetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + VersionSetId: "versionSetIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/apiVersionSets/versionSetIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiVeRsIoNsEtS/vErSiOnSeTiDvAlUe", + Expected: &WorkspaceApiVersionSetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + VersionSetId: "vErSiOnSeTiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/aPiVeRsIoNsEtS/vErSiOnSeTiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceApiVersionSetIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.VersionSetId != v.Expected.VersionSetId { + t.Fatalf("Expected %q but got %q for VersionSetId", v.Expected.VersionSetId, actual.VersionSetId) + } + + } +} + +func TestSegmentsForWorkspaceApiVersionSetId(t *testing.T) { + segments := WorkspaceApiVersionSetId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceApiVersionSetId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionsets/method_apiversionsetdelete.go b/resource-manager/apimanagement/2024-05-01/apiversionsets/method_apiversionsetdelete.go new file mode 100644 index 00000000000..1d2948225c9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionsets/method_apiversionsetdelete.go @@ -0,0 +1,76 @@ +package apiversionsets + +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 ApiVersionSetDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type ApiVersionSetDeleteOperationOptions struct { + IfMatch *string +} + +func DefaultApiVersionSetDeleteOperationOptions() ApiVersionSetDeleteOperationOptions { + return ApiVersionSetDeleteOperationOptions{} +} + +func (o ApiVersionSetDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o ApiVersionSetDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ApiVersionSetDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// ApiVersionSetDelete ... +func (c ApiVersionSetsClient) ApiVersionSetDelete(ctx context.Context, id ApiVersionSetId, options ApiVersionSetDeleteOperationOptions) (result ApiVersionSetDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionsets/method_workspaceapiversionsetdelete.go b/resource-manager/apimanagement/2024-05-01/apiversionsets/method_workspaceapiversionsetdelete.go new file mode 100644 index 00000000000..bef988a2083 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionsets/method_workspaceapiversionsetdelete.go @@ -0,0 +1,76 @@ +package apiversionsets + +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 WorkspaceApiVersionSetDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type WorkspaceApiVersionSetDeleteOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceApiVersionSetDeleteOperationOptions() WorkspaceApiVersionSetDeleteOperationOptions { + return WorkspaceApiVersionSetDeleteOperationOptions{} +} + +func (o WorkspaceApiVersionSetDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceApiVersionSetDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceApiVersionSetDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceApiVersionSetDelete ... +func (c ApiVersionSetsClient) WorkspaceApiVersionSetDelete(ctx context.Context, id WorkspaceApiVersionSetId, options WorkspaceApiVersionSetDeleteOperationOptions) (result WorkspaceApiVersionSetDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiversionsets/version.go b/resource-manager/apimanagement/2024-05-01/apiversionsets/version.go new file mode 100644 index 00000000000..68a5e888bdb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiversionsets/version.go @@ -0,0 +1,12 @@ +package apiversionsets + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apiversionsets/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/apiwiki/README.md b/resource-manager/apimanagement/2024-05-01/apiwiki/README.md new file mode 100644 index 00000000000..36f987196a6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiwiki/README.md @@ -0,0 +1,127 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apiwiki` Documentation + +The `apiwiki` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apiwiki" +``` + + +### Client Initialization + +```go +client := apiwiki.NewApiWikiClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiWikiClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := apiwiki.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +payload := apiwiki.WikiContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, apiwiki.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiWikiClient.Delete` + +```go +ctx := context.TODO() +id := apiwiki.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +read, err := client.Delete(ctx, id, apiwiki.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiWikiClient.Get` + +```go +ctx := context.TODO() +id := apiwiki.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +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: `ApiWikiClient.GetEntityTag` + +```go +ctx := context.TODO() +id := apiwiki.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiWikiClient.List` + +```go +ctx := context.TODO() +id := apiwiki.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +// alternatively `client.List(ctx, id, apiwiki.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, apiwiki.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ApiWikiClient.Update` + +```go +ctx := context.TODO() +id := apiwiki.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +payload := apiwiki.WikiUpdateContract{ + // ... +} + + +read, err := client.Update(ctx, id, payload, apiwiki.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/apiwiki/client.go b/resource-manager/apimanagement/2024-05-01/apiwiki/client.go new file mode 100644 index 00000000000..d4a7082fd98 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiwiki/client.go @@ -0,0 +1,26 @@ +package apiwiki + +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 ApiWikiClient struct { + Client *resourcemanager.Client +} + +func NewApiWikiClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiWikiClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "apiwiki", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiWikiClient: %+v", err) + } + + return &ApiWikiClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/apiwiki/id_api.go b/resource-manager/apimanagement/2024-05-01/apiwiki/id_api.go new file mode 100644 index 00000000000..04b9460d298 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiwiki/id_api.go @@ -0,0 +1,139 @@ +package apiwiki + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiId{}) +} + +var _ resourceids.ResourceId = &ApiId{} + +// ApiId is a struct representing the Resource ID for a Api +type ApiId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string +} + +// NewApiID returns a new ApiId struct +func NewApiID(subscriptionId string, resourceGroupName string, serviceName string, apiId string) ApiId { + return ApiId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + } +} + +// ParseApiID parses 'input' into a ApiId +func ParseApiID(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiIDInsensitively parses 'input' case-insensitively into a ApiId +// note: this method should only be used for API response data and not user input +func ParseApiIDInsensitively(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + return nil +} + +// ValidateApiID checks that 'input' can be parsed as a Api ID +func ValidateApiID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api ID +func (id ApiId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api ID +func (id ApiId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + } +} + +// String returns a human-readable description of this Api ID +func (id ApiId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + } + return fmt.Sprintf("Api (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/apiwiki/id_api_test.go b/resource-manager/apimanagement/2024-05-01/apiwiki/id_api_test.go new file mode 100644 index 00000000000..a986ad946de --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiwiki/id_api_test.go @@ -0,0 +1,327 @@ +package apiwiki + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiId{} + +func TestNewApiID(t *testing.T) { + id := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } +} + +func TestFormatApiID(t *testing.T) { + actual := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestParseApiIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestSegmentsForApiId(t *testing.T) { + segments := ApiId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/apiwiki/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/apiwiki/method_createorupdate.go new file mode 100644 index 00000000000..4004fddb029 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiwiki/method_createorupdate.go @@ -0,0 +1,88 @@ +package apiwiki + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WikiContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c ApiWikiClient) CreateOrUpdate(ctx context.Context, id ApiId, input WikiContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + Path: fmt.Sprintf("%s/wikis/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 + } + + var model WikiContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiwiki/method_delete.go b/resource-manager/apimanagement/2024-05-01/apiwiki/method_delete.go new file mode 100644 index 00000000000..62f6f711cde --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiwiki/method_delete.go @@ -0,0 +1,76 @@ +package apiwiki + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c ApiWikiClient) Delete(ctx context.Context, id ApiId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: fmt.Sprintf("%s/wikis/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 + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiwiki/method_get.go b/resource-manager/apimanagement/2024-05-01/apiwiki/method_get.go new file mode 100644 index 00000000000..35b7a3426ae --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiwiki/method_get.go @@ -0,0 +1,55 @@ +package apiwiki + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WikiContract +} + +// Get ... +func (c ApiWikiClient) Get(ctx context.Context, id ApiId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/wikis/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 WikiContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiwiki/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/apiwiki/method_getentitytag.go new file mode 100644 index 00000000000..08294e831ff --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiwiki/method_getentitytag.go @@ -0,0 +1,47 @@ +package apiwiki + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c ApiWikiClient) GetEntityTag(ctx context.Context, id ApiId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: fmt.Sprintf("%s/wikis/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 + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiwiki/method_list.go b/resource-manager/apimanagement/2024-05-01/apiwiki/method_list.go new file mode 100644 index 00000000000..aee5fc272ef --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiwiki/method_list.go @@ -0,0 +1,141 @@ +package apiwiki + +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 *[]WikiContract +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []WikiContract +} + +type ListOperationOptions struct { + Filter *string + Skip *int64 + 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.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ApiWikiClient) List(ctx context.Context, id ApiId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/wikis", 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 *[]WikiContract `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 ApiWikiClient) ListComplete(ctx context.Context, id ApiId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, WikiContractOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiWikiClient) ListCompleteMatchingPredicate(ctx context.Context, id ApiId, options ListOperationOptions, predicate WikiContractOperationPredicate) (result ListCompleteResult, err error) { + items := make([]WikiContract, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiwiki/method_update.go b/resource-manager/apimanagement/2024-05-01/apiwiki/method_update.go new file mode 100644 index 00000000000..d3c1ff6bdaf --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiwiki/method_update.go @@ -0,0 +1,87 @@ +package apiwiki + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WikiContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c ApiWikiClient) Update(ctx context.Context, id ApiId, input WikiUpdateContract, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + Path: fmt.Sprintf("%s/wikis/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 + } + + var model WikiContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/apiwiki/model_wikicontract.go b/resource-manager/apimanagement/2024-05-01/apiwiki/model_wikicontract.go new file mode 100644 index 00000000000..ae856b7afc2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiwiki/model_wikicontract.go @@ -0,0 +1,11 @@ +package apiwiki + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WikiContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *WikiContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apiwiki/model_wikicontractproperties.go b/resource-manager/apimanagement/2024-05-01/apiwiki/model_wikicontractproperties.go new file mode 100644 index 00000000000..5d7620b490f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiwiki/model_wikicontractproperties.go @@ -0,0 +1,8 @@ +package apiwiki + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WikiContractProperties struct { + Documents *[]WikiDocumentationContract `json:"documents,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apiwiki/model_wikidocumentationcontract.go b/resource-manager/apimanagement/2024-05-01/apiwiki/model_wikidocumentationcontract.go new file mode 100644 index 00000000000..1e89d8b12c8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiwiki/model_wikidocumentationcontract.go @@ -0,0 +1,8 @@ +package apiwiki + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WikiDocumentationContract struct { + DocumentationId *string `json:"documentationId,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apiwiki/model_wikiupdatecontract.go b/resource-manager/apimanagement/2024-05-01/apiwiki/model_wikiupdatecontract.go new file mode 100644 index 00000000000..c89c4526c2a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiwiki/model_wikiupdatecontract.go @@ -0,0 +1,8 @@ +package apiwiki + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WikiUpdateContract struct { + Properties *WikiContractProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/apiwiki/predicates.go b/resource-manager/apimanagement/2024-05-01/apiwiki/predicates.go new file mode 100644 index 00000000000..7aec66dc170 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiwiki/predicates.go @@ -0,0 +1,27 @@ +package apiwiki + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WikiContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p WikiContractOperationPredicate) Matches(input WikiContract) 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/apimanagement/2024-05-01/apiwiki/version.go b/resource-manager/apimanagement/2024-05-01/apiwiki/version.go new file mode 100644 index 00000000000..3914db1bf57 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/apiwiki/version.go @@ -0,0 +1,12 @@ +package apiwiki + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/apiwiki/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/authorization/README.md b/resource-manager/apimanagement/2024-05-01/authorization/README.md new file mode 100644 index 00000000000..059753613b7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorization/README.md @@ -0,0 +1,73 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/authorization` Documentation + +The `authorization` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/authorization" +``` + + +### Client Initialization + +```go +client := authorization.NewAuthorizationClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AuthorizationClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := authorization.NewAuthorizationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue", "authorizationIdValue") + +payload := authorization.AuthorizationContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, authorization.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AuthorizationClient.Delete` + +```go +ctx := context.TODO() +id := authorization.NewAuthorizationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue", "authorizationIdValue") + +read, err := client.Delete(ctx, id, authorization.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AuthorizationClient.Get` + +```go +ctx := context.TODO() +id := authorization.NewAuthorizationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue", "authorizationIdValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/authorization/client.go b/resource-manager/apimanagement/2024-05-01/authorization/client.go new file mode 100644 index 00000000000..5c99f0c5f29 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorization/client.go @@ -0,0 +1,26 @@ +package authorization + +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 AuthorizationClient struct { + Client *resourcemanager.Client +} + +func NewAuthorizationClientWithBaseURI(sdkApi sdkEnv.Api) (*AuthorizationClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "authorization", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AuthorizationClient: %+v", err) + } + + return &AuthorizationClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/authorization/constants.go b/resource-manager/apimanagement/2024-05-01/authorization/constants.go new file mode 100644 index 00000000000..a28406af2a0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorization/constants.go @@ -0,0 +1,89 @@ +package authorization + +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 AuthorizationType string + +const ( + AuthorizationTypeOAuthTwo AuthorizationType = "OAuth2" +) + +func PossibleValuesForAuthorizationType() []string { + return []string{ + string(AuthorizationTypeOAuthTwo), + } +} + +func (s *AuthorizationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAuthorizationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAuthorizationType(input string) (*AuthorizationType, error) { + vals := map[string]AuthorizationType{ + "oauth2": AuthorizationTypeOAuthTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AuthorizationType(input) + return &out, nil +} + +type OAuth2GrantType string + +const ( + OAuth2GrantTypeAuthorizationCode OAuth2GrantType = "AuthorizationCode" + OAuth2GrantTypeClientCredentials OAuth2GrantType = "ClientCredentials" +) + +func PossibleValuesForOAuth2GrantType() []string { + return []string{ + string(OAuth2GrantTypeAuthorizationCode), + string(OAuth2GrantTypeClientCredentials), + } +} + +func (s *OAuth2GrantType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOAuth2GrantType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOAuth2GrantType(input string) (*OAuth2GrantType, error) { + vals := map[string]OAuth2GrantType{ + "authorizationcode": OAuth2GrantTypeAuthorizationCode, + "clientcredentials": OAuth2GrantTypeClientCredentials, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OAuth2GrantType(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/authorization/id_authorization.go b/resource-manager/apimanagement/2024-05-01/authorization/id_authorization.go new file mode 100644 index 00000000000..17a2d80ccbb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorization/id_authorization.go @@ -0,0 +1,148 @@ +package authorization + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AuthorizationId{}) +} + +var _ resourceids.ResourceId = &AuthorizationId{} + +// AuthorizationId is a struct representing the Resource ID for a Authorization +type AuthorizationId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + AuthorizationProviderId string + AuthorizationId string +} + +// NewAuthorizationID returns a new AuthorizationId struct +func NewAuthorizationID(subscriptionId string, resourceGroupName string, serviceName string, authorizationProviderId string, authorizationId string) AuthorizationId { + return AuthorizationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + AuthorizationProviderId: authorizationProviderId, + AuthorizationId: authorizationId, + } +} + +// ParseAuthorizationID parses 'input' into a AuthorizationId +func ParseAuthorizationID(input string) (*AuthorizationId, error) { + parser := resourceids.NewParserFromResourceIdType(&AuthorizationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AuthorizationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAuthorizationIDInsensitively parses 'input' case-insensitively into a AuthorizationId +// note: this method should only be used for API response data and not user input +func ParseAuthorizationIDInsensitively(input string) (*AuthorizationId, error) { + parser := resourceids.NewParserFromResourceIdType(&AuthorizationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AuthorizationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AuthorizationId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.AuthorizationProviderId, ok = input.Parsed["authorizationProviderId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "authorizationProviderId", input) + } + + if id.AuthorizationId, ok = input.Parsed["authorizationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "authorizationId", input) + } + + return nil +} + +// ValidateAuthorizationID checks that 'input' can be parsed as a Authorization ID +func ValidateAuthorizationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseAuthorizationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Authorization ID +func (id AuthorizationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/authorizationProviders/%s/authorizations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.AuthorizationProviderId, id.AuthorizationId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Authorization ID +func (id AuthorizationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticAuthorizationProviders", "authorizationProviders", "authorizationProviders"), + resourceids.UserSpecifiedSegment("authorizationProviderId", "authorizationProviderIdValue"), + resourceids.StaticSegment("staticAuthorizations", "authorizations", "authorizations"), + resourceids.UserSpecifiedSegment("authorizationId", "authorizationIdValue"), + } +} + +// String returns a human-readable description of this Authorization ID +func (id AuthorizationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Authorization Provider: %q", id.AuthorizationProviderId), + fmt.Sprintf("Authorization: %q", id.AuthorizationId), + } + return fmt.Sprintf("Authorization (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/authorization/id_authorization_test.go b/resource-manager/apimanagement/2024-05-01/authorization/id_authorization_test.go new file mode 100644 index 00000000000..81806a8bcc9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorization/id_authorization_test.go @@ -0,0 +1,372 @@ +package authorization + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AuthorizationId{} + +func TestNewAuthorizationID(t *testing.T) { + id := NewAuthorizationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue", "authorizationIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.AuthorizationProviderId != "authorizationProviderIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'AuthorizationProviderId'", id.AuthorizationProviderId, "authorizationProviderIdValue") + } + + if id.AuthorizationId != "authorizationIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'AuthorizationId'", id.AuthorizationId, "authorizationIdValue") + } +} + +func TestFormatAuthorizationID(t *testing.T) { + actual := NewAuthorizationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue", "authorizationIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAuthorizationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AuthorizationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue", + Expected: &AuthorizationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + AuthorizationProviderId: "authorizationProviderIdValue", + AuthorizationId: "authorizationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAuthorizationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.AuthorizationProviderId != v.Expected.AuthorizationProviderId { + t.Fatalf("Expected %q but got %q for AuthorizationProviderId", v.Expected.AuthorizationProviderId, actual.AuthorizationProviderId) + } + + if actual.AuthorizationId != v.Expected.AuthorizationId { + t.Fatalf("Expected %q but got %q for AuthorizationId", v.Expected.AuthorizationId, actual.AuthorizationId) + } + + } +} + +func TestParseAuthorizationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AuthorizationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE/aUtHoRiZaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue", + Expected: &AuthorizationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + AuthorizationProviderId: "authorizationProviderIdValue", + AuthorizationId: "authorizationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE/aUtHoRiZaTiOnS/aUtHoRiZaTiOnIdVaLuE", + Expected: &AuthorizationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + AuthorizationProviderId: "aUtHoRiZaTiOnPrOvIdErIdVaLuE", + AuthorizationId: "aUtHoRiZaTiOnIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE/aUtHoRiZaTiOnS/aUtHoRiZaTiOnIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAuthorizationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.AuthorizationProviderId != v.Expected.AuthorizationProviderId { + t.Fatalf("Expected %q but got %q for AuthorizationProviderId", v.Expected.AuthorizationProviderId, actual.AuthorizationProviderId) + } + + if actual.AuthorizationId != v.Expected.AuthorizationId { + t.Fatalf("Expected %q but got %q for AuthorizationId", v.Expected.AuthorizationId, actual.AuthorizationId) + } + + } +} + +func TestSegmentsForAuthorizationId(t *testing.T) { + segments := AuthorizationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AuthorizationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/authorization/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/authorization/method_createorupdate.go new file mode 100644 index 00000000000..de6586fe052 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorization/method_createorupdate.go @@ -0,0 +1,88 @@ +package authorization + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AuthorizationContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c AuthorizationClient) CreateOrUpdate(ctx context.Context, id AuthorizationId, input AuthorizationContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 AuthorizationContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/authorization/method_delete.go b/resource-manager/apimanagement/2024-05-01/authorization/method_delete.go new file mode 100644 index 00000000000..9595882688b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorization/method_delete.go @@ -0,0 +1,76 @@ +package authorization + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c AuthorizationClient) Delete(ctx context.Context, id AuthorizationId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/authorization/method_get.go b/resource-manager/apimanagement/2024-05-01/authorization/method_get.go new file mode 100644 index 00000000000..b6941ad9f03 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorization/method_get.go @@ -0,0 +1,54 @@ +package authorization + +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 *AuthorizationContract +} + +// Get ... +func (c AuthorizationClient) Get(ctx context.Context, id AuthorizationId) (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 AuthorizationContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/authorization/model_authorizationcontract.go b/resource-manager/apimanagement/2024-05-01/authorization/model_authorizationcontract.go new file mode 100644 index 00000000000..7780d70da9d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorization/model_authorizationcontract.go @@ -0,0 +1,11 @@ +package authorization + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizationContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AuthorizationContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/authorization/model_authorizationcontractproperties.go b/resource-manager/apimanagement/2024-05-01/authorization/model_authorizationcontractproperties.go new file mode 100644 index 00000000000..32c31bda71f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorization/model_authorizationcontractproperties.go @@ -0,0 +1,12 @@ +package authorization + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizationContractProperties struct { + AuthorizationType *AuthorizationType `json:"authorizationType,omitempty"` + Error *AuthorizationError `json:"error,omitempty"` + Oauth2grantType *OAuth2GrantType `json:"oauth2grantType,omitempty"` + Parameters *map[string]string `json:"parameters,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/authorization/model_authorizationerror.go b/resource-manager/apimanagement/2024-05-01/authorization/model_authorizationerror.go new file mode 100644 index 00000000000..34edf009d99 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorization/model_authorizationerror.go @@ -0,0 +1,9 @@ +package authorization + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizationError struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/authorization/version.go b/resource-manager/apimanagement/2024-05-01/authorization/version.go new file mode 100644 index 00000000000..21db2020256 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorization/version.go @@ -0,0 +1,12 @@ +package authorization + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/authorization/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/README.md b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/README.md new file mode 100644 index 00000000000..816b75b8f0a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy` Documentation + +The `authorizationaccesspolicy` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy" +``` + + +### Client Initialization + +```go +client := authorizationaccesspolicy.NewAuthorizationAccessPolicyClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AuthorizationAccessPolicyClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := authorizationaccesspolicy.NewAccessPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue", "authorizationIdValue", "authorizationAccessPolicyIdValue") + +payload := authorizationaccesspolicy.AuthorizationAccessPolicyContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, authorizationaccesspolicy.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AuthorizationAccessPolicyClient.Delete` + +```go +ctx := context.TODO() +id := authorizationaccesspolicy.NewAccessPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue", "authorizationIdValue", "authorizationAccessPolicyIdValue") + +read, err := client.Delete(ctx, id, authorizationaccesspolicy.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AuthorizationAccessPolicyClient.Get` + +```go +ctx := context.TODO() +id := authorizationaccesspolicy.NewAccessPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue", "authorizationIdValue", "authorizationAccessPolicyIdValue") + +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: `AuthorizationAccessPolicyClient.ListByAuthorization` + +```go +ctx := context.TODO() +id := authorizationaccesspolicy.NewAuthorizationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue", "authorizationIdValue") + +// alternatively `client.ListByAuthorization(ctx, id, authorizationaccesspolicy.DefaultListByAuthorizationOperationOptions())` can be used to do batched pagination +items, err := client.ListByAuthorizationComplete(ctx, id, authorizationaccesspolicy.DefaultListByAuthorizationOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/client.go b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/client.go new file mode 100644 index 00000000000..f50cda54305 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/client.go @@ -0,0 +1,26 @@ +package authorizationaccesspolicy + +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 AuthorizationAccessPolicyClient struct { + Client *resourcemanager.Client +} + +func NewAuthorizationAccessPolicyClientWithBaseURI(sdkApi sdkEnv.Api) (*AuthorizationAccessPolicyClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "authorizationaccesspolicy", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AuthorizationAccessPolicyClient: %+v", err) + } + + return &AuthorizationAccessPolicyClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/id_accesspolicy.go b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/id_accesspolicy.go new file mode 100644 index 00000000000..958261ca120 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/id_accesspolicy.go @@ -0,0 +1,157 @@ +package authorizationaccesspolicy + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AccessPolicyId{}) +} + +var _ resourceids.ResourceId = &AccessPolicyId{} + +// AccessPolicyId is a struct representing the Resource ID for a Access Policy +type AccessPolicyId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + AuthorizationProviderId string + AuthorizationId string + AuthorizationAccessPolicyId string +} + +// NewAccessPolicyID returns a new AccessPolicyId struct +func NewAccessPolicyID(subscriptionId string, resourceGroupName string, serviceName string, authorizationProviderId string, authorizationId string, authorizationAccessPolicyId string) AccessPolicyId { + return AccessPolicyId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + AuthorizationProviderId: authorizationProviderId, + AuthorizationId: authorizationId, + AuthorizationAccessPolicyId: authorizationAccessPolicyId, + } +} + +// ParseAccessPolicyID parses 'input' into a AccessPolicyId +func ParseAccessPolicyID(input string) (*AccessPolicyId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccessPolicyId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccessPolicyId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAccessPolicyIDInsensitively parses 'input' case-insensitively into a AccessPolicyId +// note: this method should only be used for API response data and not user input +func ParseAccessPolicyIDInsensitively(input string) (*AccessPolicyId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccessPolicyId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccessPolicyId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AccessPolicyId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.AuthorizationProviderId, ok = input.Parsed["authorizationProviderId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "authorizationProviderId", input) + } + + if id.AuthorizationId, ok = input.Parsed["authorizationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "authorizationId", input) + } + + if id.AuthorizationAccessPolicyId, ok = input.Parsed["authorizationAccessPolicyId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "authorizationAccessPolicyId", input) + } + + return nil +} + +// ValidateAccessPolicyID checks that 'input' can be parsed as a Access Policy ID +func ValidateAccessPolicyID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseAccessPolicyID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Access Policy ID +func (id AccessPolicyId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/authorizationProviders/%s/authorizations/%s/accessPolicies/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.AuthorizationProviderId, id.AuthorizationId, id.AuthorizationAccessPolicyId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Access Policy ID +func (id AccessPolicyId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticAuthorizationProviders", "authorizationProviders", "authorizationProviders"), + resourceids.UserSpecifiedSegment("authorizationProviderId", "authorizationProviderIdValue"), + resourceids.StaticSegment("staticAuthorizations", "authorizations", "authorizations"), + resourceids.UserSpecifiedSegment("authorizationId", "authorizationIdValue"), + resourceids.StaticSegment("staticAccessPolicies", "accessPolicies", "accessPolicies"), + resourceids.UserSpecifiedSegment("authorizationAccessPolicyId", "authorizationAccessPolicyIdValue"), + } +} + +// String returns a human-readable description of this Access Policy ID +func (id AccessPolicyId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Authorization Provider: %q", id.AuthorizationProviderId), + fmt.Sprintf("Authorization: %q", id.AuthorizationId), + fmt.Sprintf("Authorization Access Policy: %q", id.AuthorizationAccessPolicyId), + } + return fmt.Sprintf("Access Policy (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/id_accesspolicy_test.go b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/id_accesspolicy_test.go new file mode 100644 index 00000000000..589e7a7721a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/id_accesspolicy_test.go @@ -0,0 +1,417 @@ +package authorizationaccesspolicy + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AccessPolicyId{} + +func TestNewAccessPolicyID(t *testing.T) { + id := NewAccessPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue", "authorizationIdValue", "authorizationAccessPolicyIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.AuthorizationProviderId != "authorizationProviderIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'AuthorizationProviderId'", id.AuthorizationProviderId, "authorizationProviderIdValue") + } + + if id.AuthorizationId != "authorizationIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'AuthorizationId'", id.AuthorizationId, "authorizationIdValue") + } + + if id.AuthorizationAccessPolicyId != "authorizationAccessPolicyIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'AuthorizationAccessPolicyId'", id.AuthorizationAccessPolicyId, "authorizationAccessPolicyIdValue") + } +} + +func TestFormatAccessPolicyID(t *testing.T) { + actual := NewAccessPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue", "authorizationIdValue", "authorizationAccessPolicyIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue/accessPolicies/authorizationAccessPolicyIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAccessPolicyID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccessPolicyId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue/accessPolicies", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue/accessPolicies/authorizationAccessPolicyIdValue", + Expected: &AccessPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + AuthorizationProviderId: "authorizationProviderIdValue", + AuthorizationId: "authorizationIdValue", + AuthorizationAccessPolicyId: "authorizationAccessPolicyIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue/accessPolicies/authorizationAccessPolicyIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccessPolicyID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.AuthorizationProviderId != v.Expected.AuthorizationProviderId { + t.Fatalf("Expected %q but got %q for AuthorizationProviderId", v.Expected.AuthorizationProviderId, actual.AuthorizationProviderId) + } + + if actual.AuthorizationId != v.Expected.AuthorizationId { + t.Fatalf("Expected %q but got %q for AuthorizationId", v.Expected.AuthorizationId, actual.AuthorizationId) + } + + if actual.AuthorizationAccessPolicyId != v.Expected.AuthorizationAccessPolicyId { + t.Fatalf("Expected %q but got %q for AuthorizationAccessPolicyId", v.Expected.AuthorizationAccessPolicyId, actual.AuthorizationAccessPolicyId) + } + + } +} + +func TestParseAccessPolicyIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccessPolicyId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE/aUtHoRiZaTiOnS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE/aUtHoRiZaTiOnS/aUtHoRiZaTiOnIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue/accessPolicies", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE/aUtHoRiZaTiOnS/aUtHoRiZaTiOnIdVaLuE/aCcEsSpOlIcIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue/accessPolicies/authorizationAccessPolicyIdValue", + Expected: &AccessPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + AuthorizationProviderId: "authorizationProviderIdValue", + AuthorizationId: "authorizationIdValue", + AuthorizationAccessPolicyId: "authorizationAccessPolicyIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue/accessPolicies/authorizationAccessPolicyIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE/aUtHoRiZaTiOnS/aUtHoRiZaTiOnIdVaLuE/aCcEsSpOlIcIeS/aUtHoRiZaTiOnAcCeSsPoLiCyIdVaLuE", + Expected: &AccessPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + AuthorizationProviderId: "aUtHoRiZaTiOnPrOvIdErIdVaLuE", + AuthorizationId: "aUtHoRiZaTiOnIdVaLuE", + AuthorizationAccessPolicyId: "aUtHoRiZaTiOnAcCeSsPoLiCyIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE/aUtHoRiZaTiOnS/aUtHoRiZaTiOnIdVaLuE/aCcEsSpOlIcIeS/aUtHoRiZaTiOnAcCeSsPoLiCyIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccessPolicyIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.AuthorizationProviderId != v.Expected.AuthorizationProviderId { + t.Fatalf("Expected %q but got %q for AuthorizationProviderId", v.Expected.AuthorizationProviderId, actual.AuthorizationProviderId) + } + + if actual.AuthorizationId != v.Expected.AuthorizationId { + t.Fatalf("Expected %q but got %q for AuthorizationId", v.Expected.AuthorizationId, actual.AuthorizationId) + } + + if actual.AuthorizationAccessPolicyId != v.Expected.AuthorizationAccessPolicyId { + t.Fatalf("Expected %q but got %q for AuthorizationAccessPolicyId", v.Expected.AuthorizationAccessPolicyId, actual.AuthorizationAccessPolicyId) + } + + } +} + +func TestSegmentsForAccessPolicyId(t *testing.T) { + segments := AccessPolicyId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AccessPolicyId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/id_authorization.go b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/id_authorization.go new file mode 100644 index 00000000000..bbd21ac9fd0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/id_authorization.go @@ -0,0 +1,148 @@ +package authorizationaccesspolicy + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AuthorizationId{}) +} + +var _ resourceids.ResourceId = &AuthorizationId{} + +// AuthorizationId is a struct representing the Resource ID for a Authorization +type AuthorizationId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + AuthorizationProviderId string + AuthorizationId string +} + +// NewAuthorizationID returns a new AuthorizationId struct +func NewAuthorizationID(subscriptionId string, resourceGroupName string, serviceName string, authorizationProviderId string, authorizationId string) AuthorizationId { + return AuthorizationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + AuthorizationProviderId: authorizationProviderId, + AuthorizationId: authorizationId, + } +} + +// ParseAuthorizationID parses 'input' into a AuthorizationId +func ParseAuthorizationID(input string) (*AuthorizationId, error) { + parser := resourceids.NewParserFromResourceIdType(&AuthorizationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AuthorizationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAuthorizationIDInsensitively parses 'input' case-insensitively into a AuthorizationId +// note: this method should only be used for API response data and not user input +func ParseAuthorizationIDInsensitively(input string) (*AuthorizationId, error) { + parser := resourceids.NewParserFromResourceIdType(&AuthorizationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AuthorizationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AuthorizationId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.AuthorizationProviderId, ok = input.Parsed["authorizationProviderId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "authorizationProviderId", input) + } + + if id.AuthorizationId, ok = input.Parsed["authorizationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "authorizationId", input) + } + + return nil +} + +// ValidateAuthorizationID checks that 'input' can be parsed as a Authorization ID +func ValidateAuthorizationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseAuthorizationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Authorization ID +func (id AuthorizationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/authorizationProviders/%s/authorizations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.AuthorizationProviderId, id.AuthorizationId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Authorization ID +func (id AuthorizationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticAuthorizationProviders", "authorizationProviders", "authorizationProviders"), + resourceids.UserSpecifiedSegment("authorizationProviderId", "authorizationProviderIdValue"), + resourceids.StaticSegment("staticAuthorizations", "authorizations", "authorizations"), + resourceids.UserSpecifiedSegment("authorizationId", "authorizationIdValue"), + } +} + +// String returns a human-readable description of this Authorization ID +func (id AuthorizationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Authorization Provider: %q", id.AuthorizationProviderId), + fmt.Sprintf("Authorization: %q", id.AuthorizationId), + } + return fmt.Sprintf("Authorization (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/id_authorization_test.go b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/id_authorization_test.go new file mode 100644 index 00000000000..28124d2fd31 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/id_authorization_test.go @@ -0,0 +1,372 @@ +package authorizationaccesspolicy + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AuthorizationId{} + +func TestNewAuthorizationID(t *testing.T) { + id := NewAuthorizationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue", "authorizationIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.AuthorizationProviderId != "authorizationProviderIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'AuthorizationProviderId'", id.AuthorizationProviderId, "authorizationProviderIdValue") + } + + if id.AuthorizationId != "authorizationIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'AuthorizationId'", id.AuthorizationId, "authorizationIdValue") + } +} + +func TestFormatAuthorizationID(t *testing.T) { + actual := NewAuthorizationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue", "authorizationIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAuthorizationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AuthorizationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue", + Expected: &AuthorizationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + AuthorizationProviderId: "authorizationProviderIdValue", + AuthorizationId: "authorizationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAuthorizationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.AuthorizationProviderId != v.Expected.AuthorizationProviderId { + t.Fatalf("Expected %q but got %q for AuthorizationProviderId", v.Expected.AuthorizationProviderId, actual.AuthorizationProviderId) + } + + if actual.AuthorizationId != v.Expected.AuthorizationId { + t.Fatalf("Expected %q but got %q for AuthorizationId", v.Expected.AuthorizationId, actual.AuthorizationId) + } + + } +} + +func TestParseAuthorizationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AuthorizationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE/aUtHoRiZaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue", + Expected: &AuthorizationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + AuthorizationProviderId: "authorizationProviderIdValue", + AuthorizationId: "authorizationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE/aUtHoRiZaTiOnS/aUtHoRiZaTiOnIdVaLuE", + Expected: &AuthorizationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + AuthorizationProviderId: "aUtHoRiZaTiOnPrOvIdErIdVaLuE", + AuthorizationId: "aUtHoRiZaTiOnIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE/aUtHoRiZaTiOnS/aUtHoRiZaTiOnIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAuthorizationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.AuthorizationProviderId != v.Expected.AuthorizationProviderId { + t.Fatalf("Expected %q but got %q for AuthorizationProviderId", v.Expected.AuthorizationProviderId, actual.AuthorizationProviderId) + } + + if actual.AuthorizationId != v.Expected.AuthorizationId { + t.Fatalf("Expected %q but got %q for AuthorizationId", v.Expected.AuthorizationId, actual.AuthorizationId) + } + + } +} + +func TestSegmentsForAuthorizationId(t *testing.T) { + segments := AuthorizationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AuthorizationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/method_createorupdate.go new file mode 100644 index 00000000000..346e394cab1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/method_createorupdate.go @@ -0,0 +1,88 @@ +package authorizationaccesspolicy + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AuthorizationAccessPolicyContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c AuthorizationAccessPolicyClient) CreateOrUpdate(ctx context.Context, id AccessPolicyId, input AuthorizationAccessPolicyContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 AuthorizationAccessPolicyContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/method_delete.go b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/method_delete.go new file mode 100644 index 00000000000..3d067c9cc2b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/method_delete.go @@ -0,0 +1,76 @@ +package authorizationaccesspolicy + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c AuthorizationAccessPolicyClient) Delete(ctx context.Context, id AccessPolicyId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/method_get.go b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/method_get.go new file mode 100644 index 00000000000..3c903781063 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/method_get.go @@ -0,0 +1,54 @@ +package authorizationaccesspolicy + +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 *AuthorizationAccessPolicyContract +} + +// Get ... +func (c AuthorizationAccessPolicyClient) Get(ctx context.Context, id AccessPolicyId) (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 AuthorizationAccessPolicyContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/method_listbyauthorization.go b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/method_listbyauthorization.go new file mode 100644 index 00000000000..3a1d919d552 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/method_listbyauthorization.go @@ -0,0 +1,141 @@ +package authorizationaccesspolicy + +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 ListByAuthorizationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AuthorizationAccessPolicyContract +} + +type ListByAuthorizationCompleteResult struct { + LatestHttpResponse *http.Response + Items []AuthorizationAccessPolicyContract +} + +type ListByAuthorizationOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByAuthorizationOperationOptions() ListByAuthorizationOperationOptions { + return ListByAuthorizationOperationOptions{} +} + +func (o ListByAuthorizationOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByAuthorizationOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByAuthorizationOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByAuthorizationCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByAuthorizationCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByAuthorization ... +func (c AuthorizationAccessPolicyClient) ListByAuthorization(ctx context.Context, id AuthorizationId, options ListByAuthorizationOperationOptions) (result ListByAuthorizationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByAuthorizationCustomPager{}, + Path: fmt.Sprintf("%s/accessPolicies", 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 *[]AuthorizationAccessPolicyContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByAuthorizationComplete retrieves all the results into a single object +func (c AuthorizationAccessPolicyClient) ListByAuthorizationComplete(ctx context.Context, id AuthorizationId, options ListByAuthorizationOperationOptions) (ListByAuthorizationCompleteResult, error) { + return c.ListByAuthorizationCompleteMatchingPredicate(ctx, id, options, AuthorizationAccessPolicyContractOperationPredicate{}) +} + +// ListByAuthorizationCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AuthorizationAccessPolicyClient) ListByAuthorizationCompleteMatchingPredicate(ctx context.Context, id AuthorizationId, options ListByAuthorizationOperationOptions, predicate AuthorizationAccessPolicyContractOperationPredicate) (result ListByAuthorizationCompleteResult, err error) { + items := make([]AuthorizationAccessPolicyContract, 0) + + resp, err := c.ListByAuthorization(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByAuthorizationCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/model_authorizationaccesspolicycontract.go b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/model_authorizationaccesspolicycontract.go new file mode 100644 index 00000000000..a865c0e89a3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/model_authorizationaccesspolicycontract.go @@ -0,0 +1,11 @@ +package authorizationaccesspolicy + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizationAccessPolicyContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AuthorizationAccessPolicyContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/model_authorizationaccesspolicycontractproperties.go b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/model_authorizationaccesspolicycontractproperties.go new file mode 100644 index 00000000000..cc4197575ee --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/model_authorizationaccesspolicycontractproperties.go @@ -0,0 +1,10 @@ +package authorizationaccesspolicy + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizationAccessPolicyContractProperties struct { + AppIds *[]string `json:"appIds,omitempty"` + ObjectId *string `json:"objectId,omitempty"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/predicates.go b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/predicates.go new file mode 100644 index 00000000000..cd99b4e1f57 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/predicates.go @@ -0,0 +1,27 @@ +package authorizationaccesspolicy + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizationAccessPolicyContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AuthorizationAccessPolicyContractOperationPredicate) Matches(input AuthorizationAccessPolicyContract) 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/apimanagement/2024-05-01/authorizationaccesspolicy/version.go b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/version.go new file mode 100644 index 00000000000..c40c6ab0bd7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy/version.go @@ -0,0 +1,12 @@ +package authorizationaccesspolicy + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/authorizationaccesspolicy/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationconfirmconsentcode/README.md b/resource-manager/apimanagement/2024-05-01/authorizationconfirmconsentcode/README.md new file mode 100644 index 00000000000..b11ce918bad --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationconfirmconsentcode/README.md @@ -0,0 +1,41 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/authorizationconfirmconsentcode` Documentation + +The `authorizationconfirmconsentcode` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/authorizationconfirmconsentcode" +``` + + +### Client Initialization + +```go +client := authorizationconfirmconsentcode.NewAuthorizationConfirmConsentCodeClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AuthorizationConfirmConsentCodeClient.AuthorizationConfirmConsentCode` + +```go +ctx := context.TODO() +id := authorizationconfirmconsentcode.NewAuthorizationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue", "authorizationIdValue") + +payload := authorizationconfirmconsentcode.AuthorizationConfirmConsentCodeRequestContract{ + // ... +} + + +read, err := client.AuthorizationConfirmConsentCode(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/apimanagement/2024-05-01/authorizationconfirmconsentcode/client.go b/resource-manager/apimanagement/2024-05-01/authorizationconfirmconsentcode/client.go new file mode 100644 index 00000000000..22e7ba30e1a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationconfirmconsentcode/client.go @@ -0,0 +1,26 @@ +package authorizationconfirmconsentcode + +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 AuthorizationConfirmConsentCodeClient struct { + Client *resourcemanager.Client +} + +func NewAuthorizationConfirmConsentCodeClientWithBaseURI(sdkApi sdkEnv.Api) (*AuthorizationConfirmConsentCodeClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "authorizationconfirmconsentcode", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AuthorizationConfirmConsentCodeClient: %+v", err) + } + + return &AuthorizationConfirmConsentCodeClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationconfirmconsentcode/id_authorization.go b/resource-manager/apimanagement/2024-05-01/authorizationconfirmconsentcode/id_authorization.go new file mode 100644 index 00000000000..c49d4be720d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationconfirmconsentcode/id_authorization.go @@ -0,0 +1,148 @@ +package authorizationconfirmconsentcode + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AuthorizationId{}) +} + +var _ resourceids.ResourceId = &AuthorizationId{} + +// AuthorizationId is a struct representing the Resource ID for a Authorization +type AuthorizationId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + AuthorizationProviderId string + AuthorizationId string +} + +// NewAuthorizationID returns a new AuthorizationId struct +func NewAuthorizationID(subscriptionId string, resourceGroupName string, serviceName string, authorizationProviderId string, authorizationId string) AuthorizationId { + return AuthorizationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + AuthorizationProviderId: authorizationProviderId, + AuthorizationId: authorizationId, + } +} + +// ParseAuthorizationID parses 'input' into a AuthorizationId +func ParseAuthorizationID(input string) (*AuthorizationId, error) { + parser := resourceids.NewParserFromResourceIdType(&AuthorizationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AuthorizationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAuthorizationIDInsensitively parses 'input' case-insensitively into a AuthorizationId +// note: this method should only be used for API response data and not user input +func ParseAuthorizationIDInsensitively(input string) (*AuthorizationId, error) { + parser := resourceids.NewParserFromResourceIdType(&AuthorizationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AuthorizationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AuthorizationId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.AuthorizationProviderId, ok = input.Parsed["authorizationProviderId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "authorizationProviderId", input) + } + + if id.AuthorizationId, ok = input.Parsed["authorizationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "authorizationId", input) + } + + return nil +} + +// ValidateAuthorizationID checks that 'input' can be parsed as a Authorization ID +func ValidateAuthorizationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseAuthorizationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Authorization ID +func (id AuthorizationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/authorizationProviders/%s/authorizations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.AuthorizationProviderId, id.AuthorizationId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Authorization ID +func (id AuthorizationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticAuthorizationProviders", "authorizationProviders", "authorizationProviders"), + resourceids.UserSpecifiedSegment("authorizationProviderId", "authorizationProviderIdValue"), + resourceids.StaticSegment("staticAuthorizations", "authorizations", "authorizations"), + resourceids.UserSpecifiedSegment("authorizationId", "authorizationIdValue"), + } +} + +// String returns a human-readable description of this Authorization ID +func (id AuthorizationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Authorization Provider: %q", id.AuthorizationProviderId), + fmt.Sprintf("Authorization: %q", id.AuthorizationId), + } + return fmt.Sprintf("Authorization (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationconfirmconsentcode/id_authorization_test.go b/resource-manager/apimanagement/2024-05-01/authorizationconfirmconsentcode/id_authorization_test.go new file mode 100644 index 00000000000..962781e9522 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationconfirmconsentcode/id_authorization_test.go @@ -0,0 +1,372 @@ +package authorizationconfirmconsentcode + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AuthorizationId{} + +func TestNewAuthorizationID(t *testing.T) { + id := NewAuthorizationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue", "authorizationIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.AuthorizationProviderId != "authorizationProviderIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'AuthorizationProviderId'", id.AuthorizationProviderId, "authorizationProviderIdValue") + } + + if id.AuthorizationId != "authorizationIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'AuthorizationId'", id.AuthorizationId, "authorizationIdValue") + } +} + +func TestFormatAuthorizationID(t *testing.T) { + actual := NewAuthorizationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue", "authorizationIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAuthorizationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AuthorizationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue", + Expected: &AuthorizationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + AuthorizationProviderId: "authorizationProviderIdValue", + AuthorizationId: "authorizationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAuthorizationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.AuthorizationProviderId != v.Expected.AuthorizationProviderId { + t.Fatalf("Expected %q but got %q for AuthorizationProviderId", v.Expected.AuthorizationProviderId, actual.AuthorizationProviderId) + } + + if actual.AuthorizationId != v.Expected.AuthorizationId { + t.Fatalf("Expected %q but got %q for AuthorizationId", v.Expected.AuthorizationId, actual.AuthorizationId) + } + + } +} + +func TestParseAuthorizationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AuthorizationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE/aUtHoRiZaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue", + Expected: &AuthorizationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + AuthorizationProviderId: "authorizationProviderIdValue", + AuthorizationId: "authorizationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE/aUtHoRiZaTiOnS/aUtHoRiZaTiOnIdVaLuE", + Expected: &AuthorizationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + AuthorizationProviderId: "aUtHoRiZaTiOnPrOvIdErIdVaLuE", + AuthorizationId: "aUtHoRiZaTiOnIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE/aUtHoRiZaTiOnS/aUtHoRiZaTiOnIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAuthorizationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.AuthorizationProviderId != v.Expected.AuthorizationProviderId { + t.Fatalf("Expected %q but got %q for AuthorizationProviderId", v.Expected.AuthorizationProviderId, actual.AuthorizationProviderId) + } + + if actual.AuthorizationId != v.Expected.AuthorizationId { + t.Fatalf("Expected %q but got %q for AuthorizationId", v.Expected.AuthorizationId, actual.AuthorizationId) + } + + } +} + +func TestSegmentsForAuthorizationId(t *testing.T) { + segments := AuthorizationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AuthorizationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationconfirmconsentcode/method_authorizationconfirmconsentcode.go b/resource-manager/apimanagement/2024-05-01/authorizationconfirmconsentcode/method_authorizationconfirmconsentcode.go new file mode 100644 index 00000000000..ae681f6debd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationconfirmconsentcode/method_authorizationconfirmconsentcode.go @@ -0,0 +1,51 @@ +package authorizationconfirmconsentcode + +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 AuthorizationConfirmConsentCodeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// AuthorizationConfirmConsentCode ... +func (c AuthorizationConfirmConsentCodeClient) AuthorizationConfirmConsentCode(ctx context.Context, id AuthorizationId, input AuthorizationConfirmConsentCodeRequestContract) (result AuthorizationConfirmConsentCodeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/confirmConsentCode", 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/apimanagement/2024-05-01/authorizationconfirmconsentcode/model_authorizationconfirmconsentcoderequestcontract.go b/resource-manager/apimanagement/2024-05-01/authorizationconfirmconsentcode/model_authorizationconfirmconsentcoderequestcontract.go new file mode 100644 index 00000000000..13c18badf13 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationconfirmconsentcode/model_authorizationconfirmconsentcoderequestcontract.go @@ -0,0 +1,8 @@ +package authorizationconfirmconsentcode + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizationConfirmConsentCodeRequestContract struct { + ConsentCode *string `json:"consentCode,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationconfirmconsentcode/version.go b/resource-manager/apimanagement/2024-05-01/authorizationconfirmconsentcode/version.go new file mode 100644 index 00000000000..13300ff5773 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationconfirmconsentcode/version.go @@ -0,0 +1,12 @@ +package authorizationconfirmconsentcode + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/authorizationconfirmconsentcode/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationloginlinks/README.md b/resource-manager/apimanagement/2024-05-01/authorizationloginlinks/README.md new file mode 100644 index 00000000000..1366f5bbf7f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationloginlinks/README.md @@ -0,0 +1,41 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/authorizationloginlinks` Documentation + +The `authorizationloginlinks` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/authorizationloginlinks" +``` + + +### Client Initialization + +```go +client := authorizationloginlinks.NewAuthorizationLoginLinksClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AuthorizationLoginLinksClient.Post` + +```go +ctx := context.TODO() +id := authorizationloginlinks.NewAuthorizationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue", "authorizationIdValue") + +payload := authorizationloginlinks.AuthorizationLoginRequestContract{ + // ... +} + + +read, err := client.Post(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/apimanagement/2024-05-01/authorizationloginlinks/client.go b/resource-manager/apimanagement/2024-05-01/authorizationloginlinks/client.go new file mode 100644 index 00000000000..1e8c48f9d33 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationloginlinks/client.go @@ -0,0 +1,26 @@ +package authorizationloginlinks + +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 AuthorizationLoginLinksClient struct { + Client *resourcemanager.Client +} + +func NewAuthorizationLoginLinksClientWithBaseURI(sdkApi sdkEnv.Api) (*AuthorizationLoginLinksClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "authorizationloginlinks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AuthorizationLoginLinksClient: %+v", err) + } + + return &AuthorizationLoginLinksClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationloginlinks/id_authorization.go b/resource-manager/apimanagement/2024-05-01/authorizationloginlinks/id_authorization.go new file mode 100644 index 00000000000..c90b836745d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationloginlinks/id_authorization.go @@ -0,0 +1,148 @@ +package authorizationloginlinks + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AuthorizationId{}) +} + +var _ resourceids.ResourceId = &AuthorizationId{} + +// AuthorizationId is a struct representing the Resource ID for a Authorization +type AuthorizationId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + AuthorizationProviderId string + AuthorizationId string +} + +// NewAuthorizationID returns a new AuthorizationId struct +func NewAuthorizationID(subscriptionId string, resourceGroupName string, serviceName string, authorizationProviderId string, authorizationId string) AuthorizationId { + return AuthorizationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + AuthorizationProviderId: authorizationProviderId, + AuthorizationId: authorizationId, + } +} + +// ParseAuthorizationID parses 'input' into a AuthorizationId +func ParseAuthorizationID(input string) (*AuthorizationId, error) { + parser := resourceids.NewParserFromResourceIdType(&AuthorizationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AuthorizationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAuthorizationIDInsensitively parses 'input' case-insensitively into a AuthorizationId +// note: this method should only be used for API response data and not user input +func ParseAuthorizationIDInsensitively(input string) (*AuthorizationId, error) { + parser := resourceids.NewParserFromResourceIdType(&AuthorizationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AuthorizationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AuthorizationId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.AuthorizationProviderId, ok = input.Parsed["authorizationProviderId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "authorizationProviderId", input) + } + + if id.AuthorizationId, ok = input.Parsed["authorizationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "authorizationId", input) + } + + return nil +} + +// ValidateAuthorizationID checks that 'input' can be parsed as a Authorization ID +func ValidateAuthorizationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseAuthorizationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Authorization ID +func (id AuthorizationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/authorizationProviders/%s/authorizations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.AuthorizationProviderId, id.AuthorizationId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Authorization ID +func (id AuthorizationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticAuthorizationProviders", "authorizationProviders", "authorizationProviders"), + resourceids.UserSpecifiedSegment("authorizationProviderId", "authorizationProviderIdValue"), + resourceids.StaticSegment("staticAuthorizations", "authorizations", "authorizations"), + resourceids.UserSpecifiedSegment("authorizationId", "authorizationIdValue"), + } +} + +// String returns a human-readable description of this Authorization ID +func (id AuthorizationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Authorization Provider: %q", id.AuthorizationProviderId), + fmt.Sprintf("Authorization: %q", id.AuthorizationId), + } + return fmt.Sprintf("Authorization (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationloginlinks/id_authorization_test.go b/resource-manager/apimanagement/2024-05-01/authorizationloginlinks/id_authorization_test.go new file mode 100644 index 00000000000..6afc3214ba3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationloginlinks/id_authorization_test.go @@ -0,0 +1,372 @@ +package authorizationloginlinks + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AuthorizationId{} + +func TestNewAuthorizationID(t *testing.T) { + id := NewAuthorizationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue", "authorizationIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.AuthorizationProviderId != "authorizationProviderIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'AuthorizationProviderId'", id.AuthorizationProviderId, "authorizationProviderIdValue") + } + + if id.AuthorizationId != "authorizationIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'AuthorizationId'", id.AuthorizationId, "authorizationIdValue") + } +} + +func TestFormatAuthorizationID(t *testing.T) { + actual := NewAuthorizationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue", "authorizationIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAuthorizationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AuthorizationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue", + Expected: &AuthorizationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + AuthorizationProviderId: "authorizationProviderIdValue", + AuthorizationId: "authorizationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAuthorizationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.AuthorizationProviderId != v.Expected.AuthorizationProviderId { + t.Fatalf("Expected %q but got %q for AuthorizationProviderId", v.Expected.AuthorizationProviderId, actual.AuthorizationProviderId) + } + + if actual.AuthorizationId != v.Expected.AuthorizationId { + t.Fatalf("Expected %q but got %q for AuthorizationId", v.Expected.AuthorizationId, actual.AuthorizationId) + } + + } +} + +func TestParseAuthorizationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AuthorizationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE/aUtHoRiZaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue", + Expected: &AuthorizationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + AuthorizationProviderId: "authorizationProviderIdValue", + AuthorizationId: "authorizationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/authorizations/authorizationIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE/aUtHoRiZaTiOnS/aUtHoRiZaTiOnIdVaLuE", + Expected: &AuthorizationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + AuthorizationProviderId: "aUtHoRiZaTiOnPrOvIdErIdVaLuE", + AuthorizationId: "aUtHoRiZaTiOnIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE/aUtHoRiZaTiOnS/aUtHoRiZaTiOnIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAuthorizationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.AuthorizationProviderId != v.Expected.AuthorizationProviderId { + t.Fatalf("Expected %q but got %q for AuthorizationProviderId", v.Expected.AuthorizationProviderId, actual.AuthorizationProviderId) + } + + if actual.AuthorizationId != v.Expected.AuthorizationId { + t.Fatalf("Expected %q but got %q for AuthorizationId", v.Expected.AuthorizationId, actual.AuthorizationId) + } + + } +} + +func TestSegmentsForAuthorizationId(t *testing.T) { + segments := AuthorizationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AuthorizationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationloginlinks/method_post.go b/resource-manager/apimanagement/2024-05-01/authorizationloginlinks/method_post.go new file mode 100644 index 00000000000..ed7594c6f30 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationloginlinks/method_post.go @@ -0,0 +1,59 @@ +package authorizationloginlinks + +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 PostOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AuthorizationLoginResponseContract +} + +// Post ... +func (c AuthorizationLoginLinksClient) Post(ctx context.Context, id AuthorizationId, input AuthorizationLoginRequestContract) (result PostOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getLoginLinks", 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 AuthorizationLoginResponseContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationloginlinks/model_authorizationloginrequestcontract.go b/resource-manager/apimanagement/2024-05-01/authorizationloginlinks/model_authorizationloginrequestcontract.go new file mode 100644 index 00000000000..e324153247b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationloginlinks/model_authorizationloginrequestcontract.go @@ -0,0 +1,8 @@ +package authorizationloginlinks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizationLoginRequestContract struct { + PostLoginRedirectUrl *string `json:"postLoginRedirectUrl,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationloginlinks/model_authorizationloginresponsecontract.go b/resource-manager/apimanagement/2024-05-01/authorizationloginlinks/model_authorizationloginresponsecontract.go new file mode 100644 index 00000000000..3fabb038d9c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationloginlinks/model_authorizationloginresponsecontract.go @@ -0,0 +1,8 @@ +package authorizationloginlinks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizationLoginResponseContract struct { + LoginLink *string `json:"loginLink,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationloginlinks/version.go b/resource-manager/apimanagement/2024-05-01/authorizationloginlinks/version.go new file mode 100644 index 00000000000..2fa4dbb1171 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationloginlinks/version.go @@ -0,0 +1,12 @@ +package authorizationloginlinks + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/authorizationloginlinks/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationprovider/README.md b/resource-manager/apimanagement/2024-05-01/authorizationprovider/README.md new file mode 100644 index 00000000000..dbbe8ea0bb2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationprovider/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/authorizationprovider` Documentation + +The `authorizationprovider` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/authorizationprovider" +``` + + +### Client Initialization + +```go +client := authorizationprovider.NewAuthorizationProviderClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AuthorizationProviderClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := authorizationprovider.NewAuthorizationProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue") + +payload := authorizationprovider.AuthorizationProviderContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, authorizationprovider.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AuthorizationProviderClient.Delete` + +```go +ctx := context.TODO() +id := authorizationprovider.NewAuthorizationProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue") + +read, err := client.Delete(ctx, id, authorizationprovider.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AuthorizationProviderClient.Get` + +```go +ctx := context.TODO() +id := authorizationprovider.NewAuthorizationProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue") + +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: `AuthorizationProviderClient.ListByService` + +```go +ctx := context.TODO() +id := authorizationprovider.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, authorizationprovider.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, authorizationprovider.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/authorizationprovider/client.go b/resource-manager/apimanagement/2024-05-01/authorizationprovider/client.go new file mode 100644 index 00000000000..c3670048321 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationprovider/client.go @@ -0,0 +1,26 @@ +package authorizationprovider + +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 AuthorizationProviderClient struct { + Client *resourcemanager.Client +} + +func NewAuthorizationProviderClientWithBaseURI(sdkApi sdkEnv.Api) (*AuthorizationProviderClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "authorizationprovider", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AuthorizationProviderClient: %+v", err) + } + + return &AuthorizationProviderClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationprovider/id_authorizationprovider.go b/resource-manager/apimanagement/2024-05-01/authorizationprovider/id_authorizationprovider.go new file mode 100644 index 00000000000..5b377135192 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationprovider/id_authorizationprovider.go @@ -0,0 +1,139 @@ +package authorizationprovider + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AuthorizationProviderId{}) +} + +var _ resourceids.ResourceId = &AuthorizationProviderId{} + +// AuthorizationProviderId is a struct representing the Resource ID for a Authorization Provider +type AuthorizationProviderId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + AuthorizationProviderId string +} + +// NewAuthorizationProviderID returns a new AuthorizationProviderId struct +func NewAuthorizationProviderID(subscriptionId string, resourceGroupName string, serviceName string, authorizationProviderId string) AuthorizationProviderId { + return AuthorizationProviderId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + AuthorizationProviderId: authorizationProviderId, + } +} + +// ParseAuthorizationProviderID parses 'input' into a AuthorizationProviderId +func ParseAuthorizationProviderID(input string) (*AuthorizationProviderId, error) { + parser := resourceids.NewParserFromResourceIdType(&AuthorizationProviderId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AuthorizationProviderId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAuthorizationProviderIDInsensitively parses 'input' case-insensitively into a AuthorizationProviderId +// note: this method should only be used for API response data and not user input +func ParseAuthorizationProviderIDInsensitively(input string) (*AuthorizationProviderId, error) { + parser := resourceids.NewParserFromResourceIdType(&AuthorizationProviderId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AuthorizationProviderId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AuthorizationProviderId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.AuthorizationProviderId, ok = input.Parsed["authorizationProviderId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "authorizationProviderId", input) + } + + return nil +} + +// ValidateAuthorizationProviderID checks that 'input' can be parsed as a Authorization Provider ID +func ValidateAuthorizationProviderID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseAuthorizationProviderID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Authorization Provider ID +func (id AuthorizationProviderId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/authorizationProviders/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.AuthorizationProviderId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Authorization Provider ID +func (id AuthorizationProviderId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticAuthorizationProviders", "authorizationProviders", "authorizationProviders"), + resourceids.UserSpecifiedSegment("authorizationProviderId", "authorizationProviderIdValue"), + } +} + +// String returns a human-readable description of this Authorization Provider ID +func (id AuthorizationProviderId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Authorization Provider: %q", id.AuthorizationProviderId), + } + return fmt.Sprintf("Authorization Provider (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationprovider/id_authorizationprovider_test.go b/resource-manager/apimanagement/2024-05-01/authorizationprovider/id_authorizationprovider_test.go new file mode 100644 index 00000000000..dd4cedf93a6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationprovider/id_authorizationprovider_test.go @@ -0,0 +1,327 @@ +package authorizationprovider + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AuthorizationProviderId{} + +func TestNewAuthorizationProviderID(t *testing.T) { + id := NewAuthorizationProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.AuthorizationProviderId != "authorizationProviderIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'AuthorizationProviderId'", id.AuthorizationProviderId, "authorizationProviderIdValue") + } +} + +func TestFormatAuthorizationProviderID(t *testing.T) { + actual := NewAuthorizationProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAuthorizationProviderID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AuthorizationProviderId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue", + Expected: &AuthorizationProviderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + AuthorizationProviderId: "authorizationProviderIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAuthorizationProviderID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.AuthorizationProviderId != v.Expected.AuthorizationProviderId { + t.Fatalf("Expected %q but got %q for AuthorizationProviderId", v.Expected.AuthorizationProviderId, actual.AuthorizationProviderId) + } + + } +} + +func TestParseAuthorizationProviderIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AuthorizationProviderId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue", + Expected: &AuthorizationProviderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + AuthorizationProviderId: "authorizationProviderIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE", + Expected: &AuthorizationProviderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + AuthorizationProviderId: "aUtHoRiZaTiOnPrOvIdErIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAuthorizationProviderIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.AuthorizationProviderId != v.Expected.AuthorizationProviderId { + t.Fatalf("Expected %q but got %q for AuthorizationProviderId", v.Expected.AuthorizationProviderId, actual.AuthorizationProviderId) + } + + } +} + +func TestSegmentsForAuthorizationProviderId(t *testing.T) { + segments := AuthorizationProviderId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AuthorizationProviderId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationprovider/id_service.go b/resource-manager/apimanagement/2024-05-01/authorizationprovider/id_service.go new file mode 100644 index 00000000000..98813175218 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationprovider/id_service.go @@ -0,0 +1,130 @@ +package authorizationprovider + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationprovider/id_service_test.go b/resource-manager/apimanagement/2024-05-01/authorizationprovider/id_service_test.go new file mode 100644 index 00000000000..13d38d758f4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationprovider/id_service_test.go @@ -0,0 +1,282 @@ +package authorizationprovider + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationprovider/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/authorizationprovider/method_createorupdate.go new file mode 100644 index 00000000000..f516f5c677f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationprovider/method_createorupdate.go @@ -0,0 +1,88 @@ +package authorizationprovider + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AuthorizationProviderContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c AuthorizationProviderClient) CreateOrUpdate(ctx context.Context, id AuthorizationProviderId, input AuthorizationProviderContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 AuthorizationProviderContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationprovider/method_delete.go b/resource-manager/apimanagement/2024-05-01/authorizationprovider/method_delete.go new file mode 100644 index 00000000000..0c0c82a4e01 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationprovider/method_delete.go @@ -0,0 +1,76 @@ +package authorizationprovider + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c AuthorizationProviderClient) Delete(ctx context.Context, id AuthorizationProviderId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationprovider/method_get.go b/resource-manager/apimanagement/2024-05-01/authorizationprovider/method_get.go new file mode 100644 index 00000000000..27f68eef690 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationprovider/method_get.go @@ -0,0 +1,54 @@ +package authorizationprovider + +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 *AuthorizationProviderContract +} + +// Get ... +func (c AuthorizationProviderClient) Get(ctx context.Context, id AuthorizationProviderId) (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 AuthorizationProviderContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationprovider/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/authorizationprovider/method_listbyservice.go new file mode 100644 index 00000000000..8e28a4d589e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationprovider/method_listbyservice.go @@ -0,0 +1,141 @@ +package authorizationprovider + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AuthorizationProviderContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []AuthorizationProviderContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c AuthorizationProviderClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/authorizationProviders", 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 *[]AuthorizationProviderContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c AuthorizationProviderClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, AuthorizationProviderContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AuthorizationProviderClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate AuthorizationProviderContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]AuthorizationProviderContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationprovider/model_authorizationprovidercontract.go b/resource-manager/apimanagement/2024-05-01/authorizationprovider/model_authorizationprovidercontract.go new file mode 100644 index 00000000000..1ebaa9e7c7f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationprovider/model_authorizationprovidercontract.go @@ -0,0 +1,11 @@ +package authorizationprovider + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizationProviderContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AuthorizationProviderContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationprovider/model_authorizationprovidercontractproperties.go b/resource-manager/apimanagement/2024-05-01/authorizationprovider/model_authorizationprovidercontractproperties.go new file mode 100644 index 00000000000..86c1e00a306 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationprovider/model_authorizationprovidercontractproperties.go @@ -0,0 +1,10 @@ +package authorizationprovider + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizationProviderContractProperties struct { + DisplayName *string `json:"displayName,omitempty"` + IdentityProvider *string `json:"identityProvider,omitempty"` + Oauth2 *AuthorizationProviderOAuth2Settings `json:"oauth2,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationprovider/model_authorizationprovideroauth2granttypes.go b/resource-manager/apimanagement/2024-05-01/authorizationprovider/model_authorizationprovideroauth2granttypes.go new file mode 100644 index 00000000000..32471b62086 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationprovider/model_authorizationprovideroauth2granttypes.go @@ -0,0 +1,9 @@ +package authorizationprovider + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizationProviderOAuth2GrantTypes struct { + AuthorizationCode *map[string]string `json:"authorizationCode,omitempty"` + ClientCredentials *map[string]string `json:"clientCredentials,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationprovider/model_authorizationprovideroauth2settings.go b/resource-manager/apimanagement/2024-05-01/authorizationprovider/model_authorizationprovideroauth2settings.go new file mode 100644 index 00000000000..cfcb9d0c4c2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationprovider/model_authorizationprovideroauth2settings.go @@ -0,0 +1,9 @@ +package authorizationprovider + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizationProviderOAuth2Settings struct { + GrantTypes *AuthorizationProviderOAuth2GrantTypes `json:"grantTypes,omitempty"` + RedirectUrl *string `json:"redirectUrl,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationprovider/predicates.go b/resource-manager/apimanagement/2024-05-01/authorizationprovider/predicates.go new file mode 100644 index 00000000000..738fcd74173 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationprovider/predicates.go @@ -0,0 +1,27 @@ +package authorizationprovider + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizationProviderContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AuthorizationProviderContractOperationPredicate) Matches(input AuthorizationProviderContract) 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/apimanagement/2024-05-01/authorizationprovider/version.go b/resource-manager/apimanagement/2024-05-01/authorizationprovider/version.go new file mode 100644 index 00000000000..0d6fe190983 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationprovider/version.go @@ -0,0 +1,12 @@ +package authorizationprovider + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/authorizationprovider/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizations/README.md b/resource-manager/apimanagement/2024-05-01/authorizations/README.md new file mode 100644 index 00000000000..74e3aed07eb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizations/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/authorizations` Documentation + +The `authorizations` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/authorizations" +``` + + +### Client Initialization + +```go +client := authorizations.NewAuthorizationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AuthorizationsClient.AuthorizationListByAuthorizationProvider` + +```go +ctx := context.TODO() +id := authorizations.NewAuthorizationProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue") + +// alternatively `client.AuthorizationListByAuthorizationProvider(ctx, id, authorizations.DefaultAuthorizationListByAuthorizationProviderOperationOptions())` can be used to do batched pagination +items, err := client.AuthorizationListByAuthorizationProviderComplete(ctx, id, authorizations.DefaultAuthorizationListByAuthorizationProviderOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/authorizations/client.go b/resource-manager/apimanagement/2024-05-01/authorizations/client.go new file mode 100644 index 00000000000..3b013986c6d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizations/client.go @@ -0,0 +1,26 @@ +package authorizations + +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 AuthorizationsClient struct { + Client *resourcemanager.Client +} + +func NewAuthorizationsClientWithBaseURI(sdkApi sdkEnv.Api) (*AuthorizationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "authorizations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AuthorizationsClient: %+v", err) + } + + return &AuthorizationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizations/constants.go b/resource-manager/apimanagement/2024-05-01/authorizations/constants.go new file mode 100644 index 00000000000..9e2147e81f9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizations/constants.go @@ -0,0 +1,89 @@ +package authorizations + +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 AuthorizationType string + +const ( + AuthorizationTypeOAuthTwo AuthorizationType = "OAuth2" +) + +func PossibleValuesForAuthorizationType() []string { + return []string{ + string(AuthorizationTypeOAuthTwo), + } +} + +func (s *AuthorizationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAuthorizationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAuthorizationType(input string) (*AuthorizationType, error) { + vals := map[string]AuthorizationType{ + "oauth2": AuthorizationTypeOAuthTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AuthorizationType(input) + return &out, nil +} + +type OAuth2GrantType string + +const ( + OAuth2GrantTypeAuthorizationCode OAuth2GrantType = "AuthorizationCode" + OAuth2GrantTypeClientCredentials OAuth2GrantType = "ClientCredentials" +) + +func PossibleValuesForOAuth2GrantType() []string { + return []string{ + string(OAuth2GrantTypeAuthorizationCode), + string(OAuth2GrantTypeClientCredentials), + } +} + +func (s *OAuth2GrantType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOAuth2GrantType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOAuth2GrantType(input string) (*OAuth2GrantType, error) { + vals := map[string]OAuth2GrantType{ + "authorizationcode": OAuth2GrantTypeAuthorizationCode, + "clientcredentials": OAuth2GrantTypeClientCredentials, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OAuth2GrantType(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizations/id_authorizationprovider.go b/resource-manager/apimanagement/2024-05-01/authorizations/id_authorizationprovider.go new file mode 100644 index 00000000000..ec0427a96f6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizations/id_authorizationprovider.go @@ -0,0 +1,139 @@ +package authorizations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AuthorizationProviderId{}) +} + +var _ resourceids.ResourceId = &AuthorizationProviderId{} + +// AuthorizationProviderId is a struct representing the Resource ID for a Authorization Provider +type AuthorizationProviderId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + AuthorizationProviderId string +} + +// NewAuthorizationProviderID returns a new AuthorizationProviderId struct +func NewAuthorizationProviderID(subscriptionId string, resourceGroupName string, serviceName string, authorizationProviderId string) AuthorizationProviderId { + return AuthorizationProviderId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + AuthorizationProviderId: authorizationProviderId, + } +} + +// ParseAuthorizationProviderID parses 'input' into a AuthorizationProviderId +func ParseAuthorizationProviderID(input string) (*AuthorizationProviderId, error) { + parser := resourceids.NewParserFromResourceIdType(&AuthorizationProviderId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AuthorizationProviderId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAuthorizationProviderIDInsensitively parses 'input' case-insensitively into a AuthorizationProviderId +// note: this method should only be used for API response data and not user input +func ParseAuthorizationProviderIDInsensitively(input string) (*AuthorizationProviderId, error) { + parser := resourceids.NewParserFromResourceIdType(&AuthorizationProviderId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AuthorizationProviderId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AuthorizationProviderId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.AuthorizationProviderId, ok = input.Parsed["authorizationProviderId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "authorizationProviderId", input) + } + + return nil +} + +// ValidateAuthorizationProviderID checks that 'input' can be parsed as a Authorization Provider ID +func ValidateAuthorizationProviderID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseAuthorizationProviderID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Authorization Provider ID +func (id AuthorizationProviderId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/authorizationProviders/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.AuthorizationProviderId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Authorization Provider ID +func (id AuthorizationProviderId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticAuthorizationProviders", "authorizationProviders", "authorizationProviders"), + resourceids.UserSpecifiedSegment("authorizationProviderId", "authorizationProviderIdValue"), + } +} + +// String returns a human-readable description of this Authorization Provider ID +func (id AuthorizationProviderId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Authorization Provider: %q", id.AuthorizationProviderId), + } + return fmt.Sprintf("Authorization Provider (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizations/id_authorizationprovider_test.go b/resource-manager/apimanagement/2024-05-01/authorizations/id_authorizationprovider_test.go new file mode 100644 index 00000000000..836b6cc5109 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizations/id_authorizationprovider_test.go @@ -0,0 +1,327 @@ +package authorizations + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AuthorizationProviderId{} + +func TestNewAuthorizationProviderID(t *testing.T) { + id := NewAuthorizationProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.AuthorizationProviderId != "authorizationProviderIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'AuthorizationProviderId'", id.AuthorizationProviderId, "authorizationProviderIdValue") + } +} + +func TestFormatAuthorizationProviderID(t *testing.T) { + actual := NewAuthorizationProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationProviderIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAuthorizationProviderID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AuthorizationProviderId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue", + Expected: &AuthorizationProviderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + AuthorizationProviderId: "authorizationProviderIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAuthorizationProviderID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.AuthorizationProviderId != v.Expected.AuthorizationProviderId { + t.Fatalf("Expected %q but got %q for AuthorizationProviderId", v.Expected.AuthorizationProviderId, actual.AuthorizationProviderId) + } + + } +} + +func TestParseAuthorizationProviderIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AuthorizationProviderId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue", + Expected: &AuthorizationProviderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + AuthorizationProviderId: "authorizationProviderIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationProviders/authorizationProviderIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE", + Expected: &AuthorizationProviderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + AuthorizationProviderId: "aUtHoRiZaTiOnPrOvIdErIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnPrOvIdErS/aUtHoRiZaTiOnPrOvIdErIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAuthorizationProviderIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.AuthorizationProviderId != v.Expected.AuthorizationProviderId { + t.Fatalf("Expected %q but got %q for AuthorizationProviderId", v.Expected.AuthorizationProviderId, actual.AuthorizationProviderId) + } + + } +} + +func TestSegmentsForAuthorizationProviderId(t *testing.T) { + segments := AuthorizationProviderId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AuthorizationProviderId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizations/method_authorizationlistbyauthorizationprovider.go b/resource-manager/apimanagement/2024-05-01/authorizations/method_authorizationlistbyauthorizationprovider.go new file mode 100644 index 00000000000..61659c7182f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizations/method_authorizationlistbyauthorizationprovider.go @@ -0,0 +1,141 @@ +package authorizations + +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 AuthorizationListByAuthorizationProviderOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AuthorizationContract +} + +type AuthorizationListByAuthorizationProviderCompleteResult struct { + LatestHttpResponse *http.Response + Items []AuthorizationContract +} + +type AuthorizationListByAuthorizationProviderOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultAuthorizationListByAuthorizationProviderOperationOptions() AuthorizationListByAuthorizationProviderOperationOptions { + return AuthorizationListByAuthorizationProviderOperationOptions{} +} + +func (o AuthorizationListByAuthorizationProviderOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o AuthorizationListByAuthorizationProviderOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o AuthorizationListByAuthorizationProviderOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type AuthorizationListByAuthorizationProviderCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *AuthorizationListByAuthorizationProviderCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// AuthorizationListByAuthorizationProvider ... +func (c AuthorizationsClient) AuthorizationListByAuthorizationProvider(ctx context.Context, id AuthorizationProviderId, options AuthorizationListByAuthorizationProviderOperationOptions) (result AuthorizationListByAuthorizationProviderOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &AuthorizationListByAuthorizationProviderCustomPager{}, + Path: fmt.Sprintf("%s/authorizations", 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 *[]AuthorizationContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// AuthorizationListByAuthorizationProviderComplete retrieves all the results into a single object +func (c AuthorizationsClient) AuthorizationListByAuthorizationProviderComplete(ctx context.Context, id AuthorizationProviderId, options AuthorizationListByAuthorizationProviderOperationOptions) (AuthorizationListByAuthorizationProviderCompleteResult, error) { + return c.AuthorizationListByAuthorizationProviderCompleteMatchingPredicate(ctx, id, options, AuthorizationContractOperationPredicate{}) +} + +// AuthorizationListByAuthorizationProviderCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AuthorizationsClient) AuthorizationListByAuthorizationProviderCompleteMatchingPredicate(ctx context.Context, id AuthorizationProviderId, options AuthorizationListByAuthorizationProviderOperationOptions, predicate AuthorizationContractOperationPredicate) (result AuthorizationListByAuthorizationProviderCompleteResult, err error) { + items := make([]AuthorizationContract, 0) + + resp, err := c.AuthorizationListByAuthorizationProvider(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = AuthorizationListByAuthorizationProviderCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizations/model_authorizationcontract.go b/resource-manager/apimanagement/2024-05-01/authorizations/model_authorizationcontract.go new file mode 100644 index 00000000000..f309226a3d9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizations/model_authorizationcontract.go @@ -0,0 +1,11 @@ +package authorizations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizationContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AuthorizationContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizations/model_authorizationcontractproperties.go b/resource-manager/apimanagement/2024-05-01/authorizations/model_authorizationcontractproperties.go new file mode 100644 index 00000000000..5ee7295af30 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizations/model_authorizationcontractproperties.go @@ -0,0 +1,12 @@ +package authorizations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizationContractProperties struct { + AuthorizationType *AuthorizationType `json:"authorizationType,omitempty"` + Error *AuthorizationError `json:"error,omitempty"` + Oauth2grantType *OAuth2GrantType `json:"oauth2grantType,omitempty"` + Parameters *map[string]string `json:"parameters,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizations/model_authorizationerror.go b/resource-manager/apimanagement/2024-05-01/authorizations/model_authorizationerror.go new file mode 100644 index 00000000000..e98db3c6f7a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizations/model_authorizationerror.go @@ -0,0 +1,9 @@ +package authorizations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizationError struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizations/predicates.go b/resource-manager/apimanagement/2024-05-01/authorizations/predicates.go new file mode 100644 index 00000000000..cc96b1d2dc4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizations/predicates.go @@ -0,0 +1,27 @@ +package authorizations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizationContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AuthorizationContractOperationPredicate) Matches(input AuthorizationContract) 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/apimanagement/2024-05-01/authorizations/version.go b/resource-manager/apimanagement/2024-05-01/authorizations/version.go new file mode 100644 index 00000000000..80e4fcac345 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizations/version.go @@ -0,0 +1,12 @@ +package authorizations + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/authorizations/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationserver/README.md b/resource-manager/apimanagement/2024-05-01/authorizationserver/README.md new file mode 100644 index 00000000000..3b4431d5a62 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationserver/README.md @@ -0,0 +1,143 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/authorizationserver` Documentation + +The `authorizationserver` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/authorizationserver" +``` + + +### Client Initialization + +```go +client := authorizationserver.NewAuthorizationServerClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AuthorizationServerClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := authorizationserver.NewAuthorizationServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationServerValue") + +payload := authorizationserver.AuthorizationServerContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, authorizationserver.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AuthorizationServerClient.Delete` + +```go +ctx := context.TODO() +id := authorizationserver.NewAuthorizationServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationServerValue") + +read, err := client.Delete(ctx, id, authorizationserver.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AuthorizationServerClient.Get` + +```go +ctx := context.TODO() +id := authorizationserver.NewAuthorizationServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationServerValue") + +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: `AuthorizationServerClient.GetEntityTag` + +```go +ctx := context.TODO() +id := authorizationserver.NewAuthorizationServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationServerValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AuthorizationServerClient.ListByService` + +```go +ctx := context.TODO() +id := authorizationserver.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, authorizationserver.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, authorizationserver.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `AuthorizationServerClient.ListSecrets` + +```go +ctx := context.TODO() +id := authorizationserver.NewAuthorizationServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationServerValue") + +read, err := client.ListSecrets(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AuthorizationServerClient.Update` + +```go +ctx := context.TODO() +id := authorizationserver.NewAuthorizationServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationServerValue") + +payload := authorizationserver.AuthorizationServerUpdateContract{ + // ... +} + + +read, err := client.Update(ctx, id, payload, authorizationserver.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/authorizationserver/client.go b/resource-manager/apimanagement/2024-05-01/authorizationserver/client.go new file mode 100644 index 00000000000..a234058adb1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationserver/client.go @@ -0,0 +1,26 @@ +package authorizationserver + +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 AuthorizationServerClient struct { + Client *resourcemanager.Client +} + +func NewAuthorizationServerClientWithBaseURI(sdkApi sdkEnv.Api) (*AuthorizationServerClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "authorizationserver", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AuthorizationServerClient: %+v", err) + } + + return &AuthorizationServerClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationserver/constants.go b/resource-manager/apimanagement/2024-05-01/authorizationserver/constants.go new file mode 100644 index 00000000000..135527703de --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationserver/constants.go @@ -0,0 +1,198 @@ +package authorizationserver + +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 AuthorizationMethod string + +const ( + AuthorizationMethodDELETE AuthorizationMethod = "DELETE" + AuthorizationMethodGET AuthorizationMethod = "GET" + AuthorizationMethodHEAD AuthorizationMethod = "HEAD" + AuthorizationMethodOPTIONS AuthorizationMethod = "OPTIONS" + AuthorizationMethodPATCH AuthorizationMethod = "PATCH" + AuthorizationMethodPOST AuthorizationMethod = "POST" + AuthorizationMethodPUT AuthorizationMethod = "PUT" + AuthorizationMethodTRACE AuthorizationMethod = "TRACE" +) + +func PossibleValuesForAuthorizationMethod() []string { + return []string{ + string(AuthorizationMethodDELETE), + string(AuthorizationMethodGET), + string(AuthorizationMethodHEAD), + string(AuthorizationMethodOPTIONS), + string(AuthorizationMethodPATCH), + string(AuthorizationMethodPOST), + string(AuthorizationMethodPUT), + string(AuthorizationMethodTRACE), + } +} + +func (s *AuthorizationMethod) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAuthorizationMethod(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAuthorizationMethod(input string) (*AuthorizationMethod, error) { + vals := map[string]AuthorizationMethod{ + "delete": AuthorizationMethodDELETE, + "get": AuthorizationMethodGET, + "head": AuthorizationMethodHEAD, + "options": AuthorizationMethodOPTIONS, + "patch": AuthorizationMethodPATCH, + "post": AuthorizationMethodPOST, + "put": AuthorizationMethodPUT, + "trace": AuthorizationMethodTRACE, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AuthorizationMethod(input) + return &out, nil +} + +type BearerTokenSendingMethod string + +const ( + BearerTokenSendingMethodAuthorizationHeader BearerTokenSendingMethod = "authorizationHeader" + BearerTokenSendingMethodQuery BearerTokenSendingMethod = "query" +) + +func PossibleValuesForBearerTokenSendingMethod() []string { + return []string{ + string(BearerTokenSendingMethodAuthorizationHeader), + string(BearerTokenSendingMethodQuery), + } +} + +func (s *BearerTokenSendingMethod) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBearerTokenSendingMethod(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBearerTokenSendingMethod(input string) (*BearerTokenSendingMethod, error) { + vals := map[string]BearerTokenSendingMethod{ + "authorizationheader": BearerTokenSendingMethodAuthorizationHeader, + "query": BearerTokenSendingMethodQuery, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BearerTokenSendingMethod(input) + return &out, nil +} + +type ClientAuthenticationMethod string + +const ( + ClientAuthenticationMethodBasic ClientAuthenticationMethod = "Basic" + ClientAuthenticationMethodBody ClientAuthenticationMethod = "Body" +) + +func PossibleValuesForClientAuthenticationMethod() []string { + return []string{ + string(ClientAuthenticationMethodBasic), + string(ClientAuthenticationMethodBody), + } +} + +func (s *ClientAuthenticationMethod) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseClientAuthenticationMethod(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseClientAuthenticationMethod(input string) (*ClientAuthenticationMethod, error) { + vals := map[string]ClientAuthenticationMethod{ + "basic": ClientAuthenticationMethodBasic, + "body": ClientAuthenticationMethodBody, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ClientAuthenticationMethod(input) + return &out, nil +} + +type GrantType string + +const ( + GrantTypeAuthorizationCode GrantType = "authorizationCode" + GrantTypeClientCredentials GrantType = "clientCredentials" + GrantTypeImplicit GrantType = "implicit" + GrantTypeResourceOwnerPassword GrantType = "resourceOwnerPassword" +) + +func PossibleValuesForGrantType() []string { + return []string{ + string(GrantTypeAuthorizationCode), + string(GrantTypeClientCredentials), + string(GrantTypeImplicit), + string(GrantTypeResourceOwnerPassword), + } +} + +func (s *GrantType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGrantType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseGrantType(input string) (*GrantType, error) { + vals := map[string]GrantType{ + "authorizationcode": GrantTypeAuthorizationCode, + "clientcredentials": GrantTypeClientCredentials, + "implicit": GrantTypeImplicit, + "resourceownerpassword": GrantTypeResourceOwnerPassword, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := GrantType(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationserver/id_authorizationserver.go b/resource-manager/apimanagement/2024-05-01/authorizationserver/id_authorizationserver.go new file mode 100644 index 00000000000..d501746a896 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationserver/id_authorizationserver.go @@ -0,0 +1,139 @@ +package authorizationserver + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AuthorizationServerId{}) +} + +var _ resourceids.ResourceId = &AuthorizationServerId{} + +// AuthorizationServerId is a struct representing the Resource ID for a Authorization Server +type AuthorizationServerId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + AuthorizationServerName string +} + +// NewAuthorizationServerID returns a new AuthorizationServerId struct +func NewAuthorizationServerID(subscriptionId string, resourceGroupName string, serviceName string, authorizationServerName string) AuthorizationServerId { + return AuthorizationServerId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + AuthorizationServerName: authorizationServerName, + } +} + +// ParseAuthorizationServerID parses 'input' into a AuthorizationServerId +func ParseAuthorizationServerID(input string) (*AuthorizationServerId, error) { + parser := resourceids.NewParserFromResourceIdType(&AuthorizationServerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AuthorizationServerId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAuthorizationServerIDInsensitively parses 'input' case-insensitively into a AuthorizationServerId +// note: this method should only be used for API response data and not user input +func ParseAuthorizationServerIDInsensitively(input string) (*AuthorizationServerId, error) { + parser := resourceids.NewParserFromResourceIdType(&AuthorizationServerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AuthorizationServerId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AuthorizationServerId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.AuthorizationServerName, ok = input.Parsed["authorizationServerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "authorizationServerName", input) + } + + return nil +} + +// ValidateAuthorizationServerID checks that 'input' can be parsed as a Authorization Server ID +func ValidateAuthorizationServerID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseAuthorizationServerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Authorization Server ID +func (id AuthorizationServerId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/authorizationServers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.AuthorizationServerName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Authorization Server ID +func (id AuthorizationServerId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticAuthorizationServers", "authorizationServers", "authorizationServers"), + resourceids.UserSpecifiedSegment("authorizationServerName", "authorizationServerValue"), + } +} + +// String returns a human-readable description of this Authorization Server ID +func (id AuthorizationServerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Authorization Server Name: %q", id.AuthorizationServerName), + } + return fmt.Sprintf("Authorization Server (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationserver/id_authorizationserver_test.go b/resource-manager/apimanagement/2024-05-01/authorizationserver/id_authorizationserver_test.go new file mode 100644 index 00000000000..3894d9b8faa --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationserver/id_authorizationserver_test.go @@ -0,0 +1,327 @@ +package authorizationserver + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AuthorizationServerId{} + +func TestNewAuthorizationServerID(t *testing.T) { + id := NewAuthorizationServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationServerValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.AuthorizationServerName != "authorizationServerValue" { + t.Fatalf("Expected %q but got %q for Segment 'AuthorizationServerName'", id.AuthorizationServerName, "authorizationServerValue") + } +} + +func TestFormatAuthorizationServerID(t *testing.T) { + actual := NewAuthorizationServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "authorizationServerValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationServers/authorizationServerValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAuthorizationServerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AuthorizationServerId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationServers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationServers/authorizationServerValue", + Expected: &AuthorizationServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + AuthorizationServerName: "authorizationServerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationServers/authorizationServerValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAuthorizationServerID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.AuthorizationServerName != v.Expected.AuthorizationServerName { + t.Fatalf("Expected %q but got %q for AuthorizationServerName", v.Expected.AuthorizationServerName, actual.AuthorizationServerName) + } + + } +} + +func TestParseAuthorizationServerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AuthorizationServerId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationServers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnSeRvErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationServers/authorizationServerValue", + Expected: &AuthorizationServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + AuthorizationServerName: "authorizationServerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/authorizationServers/authorizationServerValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnSeRvErS/aUtHoRiZaTiOnSeRvErVaLuE", + Expected: &AuthorizationServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + AuthorizationServerName: "aUtHoRiZaTiOnSeRvErVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aUtHoRiZaTiOnSeRvErS/aUtHoRiZaTiOnSeRvErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAuthorizationServerIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.AuthorizationServerName != v.Expected.AuthorizationServerName { + t.Fatalf("Expected %q but got %q for AuthorizationServerName", v.Expected.AuthorizationServerName, actual.AuthorizationServerName) + } + + } +} + +func TestSegmentsForAuthorizationServerId(t *testing.T) { + segments := AuthorizationServerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AuthorizationServerId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationserver/id_service.go b/resource-manager/apimanagement/2024-05-01/authorizationserver/id_service.go new file mode 100644 index 00000000000..16870e5f263 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationserver/id_service.go @@ -0,0 +1,130 @@ +package authorizationserver + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationserver/id_service_test.go b/resource-manager/apimanagement/2024-05-01/authorizationserver/id_service_test.go new file mode 100644 index 00000000000..f824cfd7124 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationserver/id_service_test.go @@ -0,0 +1,282 @@ +package authorizationserver + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationserver/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/authorizationserver/method_createorupdate.go new file mode 100644 index 00000000000..ef58fe9a05f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationserver/method_createorupdate.go @@ -0,0 +1,88 @@ +package authorizationserver + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AuthorizationServerContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c AuthorizationServerClient) CreateOrUpdate(ctx context.Context, id AuthorizationServerId, input AuthorizationServerContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 AuthorizationServerContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationserver/method_delete.go b/resource-manager/apimanagement/2024-05-01/authorizationserver/method_delete.go new file mode 100644 index 00000000000..a307aa17d3f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationserver/method_delete.go @@ -0,0 +1,76 @@ +package authorizationserver + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c AuthorizationServerClient) Delete(ctx context.Context, id AuthorizationServerId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationserver/method_get.go b/resource-manager/apimanagement/2024-05-01/authorizationserver/method_get.go new file mode 100644 index 00000000000..8d4a7463981 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationserver/method_get.go @@ -0,0 +1,54 @@ +package authorizationserver + +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 *AuthorizationServerContract +} + +// Get ... +func (c AuthorizationServerClient) Get(ctx context.Context, id AuthorizationServerId) (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 AuthorizationServerContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationserver/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/authorizationserver/method_getentitytag.go new file mode 100644 index 00000000000..4eb7f0abe34 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationserver/method_getentitytag.go @@ -0,0 +1,46 @@ +package authorizationserver + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c AuthorizationServerClient) GetEntityTag(ctx context.Context, id AuthorizationServerId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationserver/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/authorizationserver/method_listbyservice.go new file mode 100644 index 00000000000..ae4ad390656 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationserver/method_listbyservice.go @@ -0,0 +1,141 @@ +package authorizationserver + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AuthorizationServerContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []AuthorizationServerContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c AuthorizationServerClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/authorizationServers", 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 *[]AuthorizationServerContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c AuthorizationServerClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, AuthorizationServerContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AuthorizationServerClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate AuthorizationServerContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]AuthorizationServerContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationserver/method_listsecrets.go b/resource-manager/apimanagement/2024-05-01/authorizationserver/method_listsecrets.go new file mode 100644 index 00000000000..58b62cc36bf --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationserver/method_listsecrets.go @@ -0,0 +1,55 @@ +package authorizationserver + +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 ListSecretsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AuthorizationServerSecretsContract +} + +// ListSecrets ... +func (c AuthorizationServerClient) ListSecrets(ctx context.Context, id AuthorizationServerId) (result ListSecretsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listSecrets", 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 AuthorizationServerSecretsContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationserver/method_update.go b/resource-manager/apimanagement/2024-05-01/authorizationserver/method_update.go new file mode 100644 index 00000000000..686f7550e4d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationserver/method_update.go @@ -0,0 +1,87 @@ +package authorizationserver + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AuthorizationServerContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c AuthorizationServerClient) Update(ctx context.Context, id AuthorizationServerId, input AuthorizationServerUpdateContract, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 AuthorizationServerContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationserver/model_authorizationservercontract.go b/resource-manager/apimanagement/2024-05-01/authorizationserver/model_authorizationservercontract.go new file mode 100644 index 00000000000..fe29efdfe90 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationserver/model_authorizationservercontract.go @@ -0,0 +1,11 @@ +package authorizationserver + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizationServerContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AuthorizationServerContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationserver/model_authorizationservercontractproperties.go b/resource-manager/apimanagement/2024-05-01/authorizationserver/model_authorizationservercontractproperties.go new file mode 100644 index 00000000000..521b644da5e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationserver/model_authorizationservercontractproperties.go @@ -0,0 +1,25 @@ +package authorizationserver + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizationServerContractProperties struct { + AuthorizationEndpoint string `json:"authorizationEndpoint"` + AuthorizationMethods *[]AuthorizationMethod `json:"authorizationMethods,omitempty"` + BearerTokenSendingMethods *[]BearerTokenSendingMethod `json:"bearerTokenSendingMethods,omitempty"` + ClientAuthenticationMethod *[]ClientAuthenticationMethod `json:"clientAuthenticationMethod,omitempty"` + ClientId string `json:"clientId"` + ClientRegistrationEndpoint string `json:"clientRegistrationEndpoint"` + ClientSecret *string `json:"clientSecret,omitempty"` + DefaultScope *string `json:"defaultScope,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName string `json:"displayName"` + GrantTypes []GrantType `json:"grantTypes"` + ResourceOwnerPassword *string `json:"resourceOwnerPassword,omitempty"` + ResourceOwnerUsername *string `json:"resourceOwnerUsername,omitempty"` + SupportState *bool `json:"supportState,omitempty"` + TokenBodyParameters *[]TokenBodyParameterContract `json:"tokenBodyParameters,omitempty"` + TokenEndpoint *string `json:"tokenEndpoint,omitempty"` + UseInApiDocumentation *bool `json:"useInApiDocumentation,omitempty"` + UseInTestConsole *bool `json:"useInTestConsole,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationserver/model_authorizationserversecretscontract.go b/resource-manager/apimanagement/2024-05-01/authorizationserver/model_authorizationserversecretscontract.go new file mode 100644 index 00000000000..5dadcb0def4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationserver/model_authorizationserversecretscontract.go @@ -0,0 +1,10 @@ +package authorizationserver + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizationServerSecretsContract struct { + ClientSecret *string `json:"clientSecret,omitempty"` + ResourceOwnerPassword *string `json:"resourceOwnerPassword,omitempty"` + ResourceOwnerUsername *string `json:"resourceOwnerUsername,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationserver/model_authorizationserverupdatecontract.go b/resource-manager/apimanagement/2024-05-01/authorizationserver/model_authorizationserverupdatecontract.go new file mode 100644 index 00000000000..595ea238e78 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationserver/model_authorizationserverupdatecontract.go @@ -0,0 +1,11 @@ +package authorizationserver + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizationServerUpdateContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AuthorizationServerUpdateContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationserver/model_authorizationserverupdatecontractproperties.go b/resource-manager/apimanagement/2024-05-01/authorizationserver/model_authorizationserverupdatecontractproperties.go new file mode 100644 index 00000000000..c9870d7e9a5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationserver/model_authorizationserverupdatecontractproperties.go @@ -0,0 +1,25 @@ +package authorizationserver + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizationServerUpdateContractProperties struct { + AuthorizationEndpoint *string `json:"authorizationEndpoint,omitempty"` + AuthorizationMethods *[]AuthorizationMethod `json:"authorizationMethods,omitempty"` + BearerTokenSendingMethods *[]BearerTokenSendingMethod `json:"bearerTokenSendingMethods,omitempty"` + ClientAuthenticationMethod *[]ClientAuthenticationMethod `json:"clientAuthenticationMethod,omitempty"` + ClientId *string `json:"clientId,omitempty"` + ClientRegistrationEndpoint *string `json:"clientRegistrationEndpoint,omitempty"` + ClientSecret *string `json:"clientSecret,omitempty"` + DefaultScope *string `json:"defaultScope,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + GrantTypes *[]GrantType `json:"grantTypes,omitempty"` + ResourceOwnerPassword *string `json:"resourceOwnerPassword,omitempty"` + ResourceOwnerUsername *string `json:"resourceOwnerUsername,omitempty"` + SupportState *bool `json:"supportState,omitempty"` + TokenBodyParameters *[]TokenBodyParameterContract `json:"tokenBodyParameters,omitempty"` + TokenEndpoint *string `json:"tokenEndpoint,omitempty"` + UseInApiDocumentation *bool `json:"useInApiDocumentation,omitempty"` + UseInTestConsole *bool `json:"useInTestConsole,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationserver/model_tokenbodyparametercontract.go b/resource-manager/apimanagement/2024-05-01/authorizationserver/model_tokenbodyparametercontract.go new file mode 100644 index 00000000000..63d853bc49f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationserver/model_tokenbodyparametercontract.go @@ -0,0 +1,9 @@ +package authorizationserver + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TokenBodyParameterContract struct { + Name string `json:"name"` + Value string `json:"value"` +} diff --git a/resource-manager/apimanagement/2024-05-01/authorizationserver/predicates.go b/resource-manager/apimanagement/2024-05-01/authorizationserver/predicates.go new file mode 100644 index 00000000000..a1ec772dca9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationserver/predicates.go @@ -0,0 +1,27 @@ +package authorizationserver + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthorizationServerContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AuthorizationServerContractOperationPredicate) Matches(input AuthorizationServerContract) 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/apimanagement/2024-05-01/authorizationserver/version.go b/resource-manager/apimanagement/2024-05-01/authorizationserver/version.go new file mode 100644 index 00000000000..646e10bf52f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/authorizationserver/version.go @@ -0,0 +1,12 @@ +package authorizationserver + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/authorizationserver/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/README.md b/resource-manager/apimanagement/2024-05-01/backend/README.md new file mode 100644 index 00000000000..45ef74abf4c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/README.md @@ -0,0 +1,234 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/backend` Documentation + +The `backend` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/backend" +``` + + +### Client Initialization + +```go +client := backend.NewBackendClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackendClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := backend.NewBackendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "backendIdValue") + +payload := backend.BackendContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, backend.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BackendClient.Delete` + +```go +ctx := context.TODO() +id := backend.NewBackendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "backendIdValue") + +read, err := client.Delete(ctx, id, backend.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BackendClient.Get` + +```go +ctx := context.TODO() +id := backend.NewBackendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "backendIdValue") + +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: `BackendClient.GetEntityTag` + +```go +ctx := context.TODO() +id := backend.NewBackendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "backendIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BackendClient.ListByService` + +```go +ctx := context.TODO() +id := backend.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, backend.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, backend.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `BackendClient.Update` + +```go +ctx := context.TODO() +id := backend.NewBackendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "backendIdValue") + +payload := backend.BackendUpdateParameters{ + // ... +} + + +read, err := client.Update(ctx, id, payload, backend.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BackendClient.WorkspaceBackendCreateOrUpdate` + +```go +ctx := context.TODO() +id := backend.NewWorkspaceBackendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "backendIdValue") + +payload := backend.BackendContract{ + // ... +} + + +read, err := client.WorkspaceBackendCreateOrUpdate(ctx, id, payload, backend.DefaultWorkspaceBackendCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BackendClient.WorkspaceBackendDelete` + +```go +ctx := context.TODO() +id := backend.NewWorkspaceBackendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "backendIdValue") + +read, err := client.WorkspaceBackendDelete(ctx, id, backend.DefaultWorkspaceBackendDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BackendClient.WorkspaceBackendGet` + +```go +ctx := context.TODO() +id := backend.NewWorkspaceBackendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "backendIdValue") + +read, err := client.WorkspaceBackendGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BackendClient.WorkspaceBackendGetEntityTag` + +```go +ctx := context.TODO() +id := backend.NewWorkspaceBackendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "backendIdValue") + +read, err := client.WorkspaceBackendGetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BackendClient.WorkspaceBackendListByWorkspace` + +```go +ctx := context.TODO() +id := backend.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +// alternatively `client.WorkspaceBackendListByWorkspace(ctx, id, backend.DefaultWorkspaceBackendListByWorkspaceOperationOptions())` can be used to do batched pagination +items, err := client.WorkspaceBackendListByWorkspaceComplete(ctx, id, backend.DefaultWorkspaceBackendListByWorkspaceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `BackendClient.WorkspaceBackendUpdate` + +```go +ctx := context.TODO() +id := backend.NewWorkspaceBackendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "backendIdValue") + +payload := backend.BackendUpdateParameters{ + // ... +} + + +read, err := client.WorkspaceBackendUpdate(ctx, id, payload, backend.DefaultWorkspaceBackendUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/backend/client.go b/resource-manager/apimanagement/2024-05-01/backend/client.go new file mode 100644 index 00000000000..8cf9c601f15 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/client.go @@ -0,0 +1,26 @@ +package backend + +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 BackendClient struct { + Client *resourcemanager.Client +} + +func NewBackendClientWithBaseURI(sdkApi sdkEnv.Api) (*BackendClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "backend", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BackendClient: %+v", err) + } + + return &BackendClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/constants.go b/resource-manager/apimanagement/2024-05-01/backend/constants.go new file mode 100644 index 00000000000..225cfa96d56 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/constants.go @@ -0,0 +1,92 @@ +package backend + +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 BackendProtocol string + +const ( + BackendProtocolHTTP BackendProtocol = "http" + BackendProtocolSoap BackendProtocol = "soap" +) + +func PossibleValuesForBackendProtocol() []string { + return []string{ + string(BackendProtocolHTTP), + string(BackendProtocolSoap), + } +} + +func (s *BackendProtocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBackendProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBackendProtocol(input string) (*BackendProtocol, error) { + vals := map[string]BackendProtocol{ + "http": BackendProtocolHTTP, + "soap": BackendProtocolSoap, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackendProtocol(input) + return &out, nil +} + +type BackendType string + +const ( + BackendTypePool BackendType = "Pool" + BackendTypeSingle BackendType = "Single" +) + +func PossibleValuesForBackendType() []string { + return []string{ + string(BackendTypePool), + string(BackendTypeSingle), + } +} + +func (s *BackendType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBackendType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBackendType(input string) (*BackendType, error) { + vals := map[string]BackendType{ + "pool": BackendTypePool, + "single": BackendTypeSingle, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackendType(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/id_backend.go b/resource-manager/apimanagement/2024-05-01/backend/id_backend.go new file mode 100644 index 00000000000..d59958e9b68 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/id_backend.go @@ -0,0 +1,139 @@ +package backend + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BackendId{}) +} + +var _ resourceids.ResourceId = &BackendId{} + +// BackendId is a struct representing the Resource ID for a Backend +type BackendId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + BackendId string +} + +// NewBackendID returns a new BackendId struct +func NewBackendID(subscriptionId string, resourceGroupName string, serviceName string, backendId string) BackendId { + return BackendId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + BackendId: backendId, + } +} + +// ParseBackendID parses 'input' into a BackendId +func ParseBackendID(input string) (*BackendId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackendId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackendId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackendIDInsensitively parses 'input' case-insensitively into a BackendId +// note: this method should only be used for API response data and not user input +func ParseBackendIDInsensitively(input string) (*BackendId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackendId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackendId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackendId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.BackendId, ok = input.Parsed["backendId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backendId", input) + } + + return nil +} + +// ValidateBackendID checks that 'input' can be parsed as a Backend ID +func ValidateBackendID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseBackendID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backend ID +func (id BackendId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/backends/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.BackendId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backend ID +func (id BackendId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticBackends", "backends", "backends"), + resourceids.UserSpecifiedSegment("backendId", "backendIdValue"), + } +} + +// String returns a human-readable description of this Backend ID +func (id BackendId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Backend: %q", id.BackendId), + } + return fmt.Sprintf("Backend (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/id_backend_test.go b/resource-manager/apimanagement/2024-05-01/backend/id_backend_test.go new file mode 100644 index 00000000000..d7d6b3b3a1f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/id_backend_test.go @@ -0,0 +1,327 @@ +package backend + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &BackendId{} + +func TestNewBackendID(t *testing.T) { + id := NewBackendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "backendIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.BackendId != "backendIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackendId'", id.BackendId, "backendIdValue") + } +} + +func TestFormatBackendID(t *testing.T) { + actual := NewBackendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "backendIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/backends/backendIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackendID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackendId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/backends", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/backends/backendIdValue", + Expected: &BackendId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + BackendId: "backendIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/backends/backendIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackendID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.BackendId != v.Expected.BackendId { + t.Fatalf("Expected %q but got %q for BackendId", v.Expected.BackendId, actual.BackendId) + } + + } +} + +func TestParseBackendIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackendId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/backends", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/bAcKeNdS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/backends/backendIdValue", + Expected: &BackendId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + BackendId: "backendIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/backends/backendIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/bAcKeNdS/bAcKeNdIdVaLuE", + Expected: &BackendId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + BackendId: "bAcKeNdIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/bAcKeNdS/bAcKeNdIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackendIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.BackendId != v.Expected.BackendId { + t.Fatalf("Expected %q but got %q for BackendId", v.Expected.BackendId, actual.BackendId) + } + + } +} + +func TestSegmentsForBackendId(t *testing.T) { + segments := BackendId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackendId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/id_service.go b/resource-manager/apimanagement/2024-05-01/backend/id_service.go new file mode 100644 index 00000000000..afe0eb62f7f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/id_service.go @@ -0,0 +1,130 @@ +package backend + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/id_service_test.go b/resource-manager/apimanagement/2024-05-01/backend/id_service_test.go new file mode 100644 index 00000000000..9617c42b055 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/id_service_test.go @@ -0,0 +1,282 @@ +package backend + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/id_workspace.go b/resource-manager/apimanagement/2024-05-01/backend/id_workspace.go new file mode 100644 index 00000000000..7a2c6148315 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/id_workspace.go @@ -0,0 +1,139 @@ +package backend + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/id_workspace_test.go b/resource-manager/apimanagement/2024-05-01/backend/id_workspace_test.go new file mode 100644 index 00000000000..32d3616dc5e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/id_workspace_test.go @@ -0,0 +1,327 @@ +package backend + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/id_workspacebackend.go b/resource-manager/apimanagement/2024-05-01/backend/id_workspacebackend.go new file mode 100644 index 00000000000..f65f285c46f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/id_workspacebackend.go @@ -0,0 +1,148 @@ +package backend + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceBackendId{}) +} + +var _ resourceids.ResourceId = &WorkspaceBackendId{} + +// WorkspaceBackendId is a struct representing the Resource ID for a Workspace Backend +type WorkspaceBackendId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + BackendId string +} + +// NewWorkspaceBackendID returns a new WorkspaceBackendId struct +func NewWorkspaceBackendID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, backendId string) WorkspaceBackendId { + return WorkspaceBackendId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + BackendId: backendId, + } +} + +// ParseWorkspaceBackendID parses 'input' into a WorkspaceBackendId +func ParseWorkspaceBackendID(input string) (*WorkspaceBackendId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceBackendId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceBackendId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceBackendIDInsensitively parses 'input' case-insensitively into a WorkspaceBackendId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceBackendIDInsensitively(input string) (*WorkspaceBackendId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceBackendId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceBackendId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceBackendId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.BackendId, ok = input.Parsed["backendId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backendId", input) + } + + return nil +} + +// ValidateWorkspaceBackendID checks that 'input' can be parsed as a Workspace Backend ID +func ValidateWorkspaceBackendID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceBackendID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Backend ID +func (id WorkspaceBackendId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/backends/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.BackendId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Backend ID +func (id WorkspaceBackendId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticBackends", "backends", "backends"), + resourceids.UserSpecifiedSegment("backendId", "backendIdValue"), + } +} + +// String returns a human-readable description of this Workspace Backend ID +func (id WorkspaceBackendId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Backend: %q", id.BackendId), + } + return fmt.Sprintf("Workspace Backend (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/id_workspacebackend_test.go b/resource-manager/apimanagement/2024-05-01/backend/id_workspacebackend_test.go new file mode 100644 index 00000000000..619fdf02656 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/id_workspacebackend_test.go @@ -0,0 +1,372 @@ +package backend + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceBackendId{} + +func TestNewWorkspaceBackendID(t *testing.T) { + id := NewWorkspaceBackendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "backendIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.BackendId != "backendIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackendId'", id.BackendId, "backendIdValue") + } +} + +func TestFormatWorkspaceBackendID(t *testing.T) { + actual := NewWorkspaceBackendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "backendIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/backends/backendIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceBackendID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceBackendId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/backends", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/backends/backendIdValue", + Expected: &WorkspaceBackendId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + BackendId: "backendIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/backends/backendIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceBackendID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.BackendId != v.Expected.BackendId { + t.Fatalf("Expected %q but got %q for BackendId", v.Expected.BackendId, actual.BackendId) + } + + } +} + +func TestParseWorkspaceBackendIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceBackendId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/backends", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/bAcKeNdS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/backends/backendIdValue", + Expected: &WorkspaceBackendId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + BackendId: "backendIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/backends/backendIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/bAcKeNdS/bAcKeNdIdVaLuE", + Expected: &WorkspaceBackendId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + BackendId: "bAcKeNdIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/bAcKeNdS/bAcKeNdIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceBackendIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.BackendId != v.Expected.BackendId { + t.Fatalf("Expected %q but got %q for BackendId", v.Expected.BackendId, actual.BackendId) + } + + } +} + +func TestSegmentsForWorkspaceBackendId(t *testing.T) { + segments := WorkspaceBackendId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceBackendId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/backend/method_createorupdate.go new file mode 100644 index 00000000000..876a39e1fb9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/method_createorupdate.go @@ -0,0 +1,88 @@ +package backend + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *BackendContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c BackendClient) CreateOrUpdate(ctx context.Context, id BackendId, input BackendContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 BackendContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/method_delete.go b/resource-manager/apimanagement/2024-05-01/backend/method_delete.go new file mode 100644 index 00000000000..f71fa94d865 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/method_delete.go @@ -0,0 +1,76 @@ +package backend + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c BackendClient) Delete(ctx context.Context, id BackendId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/method_get.go b/resource-manager/apimanagement/2024-05-01/backend/method_get.go new file mode 100644 index 00000000000..cc3aa998b93 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/method_get.go @@ -0,0 +1,54 @@ +package backend + +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 *BackendContract +} + +// Get ... +func (c BackendClient) Get(ctx context.Context, id BackendId) (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 BackendContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/backend/method_getentitytag.go new file mode 100644 index 00000000000..6bff18fa57d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/method_getentitytag.go @@ -0,0 +1,46 @@ +package backend + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c BackendClient) GetEntityTag(ctx context.Context, id BackendId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/backend/method_listbyservice.go new file mode 100644 index 00000000000..f8c5b6daf2a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/method_listbyservice.go @@ -0,0 +1,141 @@ +package backend + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]BackendContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []BackendContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c BackendClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/backends", 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 *[]BackendContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c BackendClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, BackendContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BackendClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate BackendContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]BackendContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/method_update.go b/resource-manager/apimanagement/2024-05-01/backend/method_update.go new file mode 100644 index 00000000000..3c102cf0e80 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/method_update.go @@ -0,0 +1,87 @@ +package backend + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *BackendContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c BackendClient) Update(ctx context.Context, id BackendId, input BackendUpdateParameters, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 BackendContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/method_workspacebackendcreateorupdate.go b/resource-manager/apimanagement/2024-05-01/backend/method_workspacebackendcreateorupdate.go new file mode 100644 index 00000000000..c5eb5e220bf --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/method_workspacebackendcreateorupdate.go @@ -0,0 +1,88 @@ +package backend + +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 WorkspaceBackendCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *BackendContract +} + +type WorkspaceBackendCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceBackendCreateOrUpdateOperationOptions() WorkspaceBackendCreateOrUpdateOperationOptions { + return WorkspaceBackendCreateOrUpdateOperationOptions{} +} + +func (o WorkspaceBackendCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceBackendCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceBackendCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceBackendCreateOrUpdate ... +func (c BackendClient) WorkspaceBackendCreateOrUpdate(ctx context.Context, id WorkspaceBackendId, input BackendContract, options WorkspaceBackendCreateOrUpdateOperationOptions) (result WorkspaceBackendCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 BackendContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/method_workspacebackenddelete.go b/resource-manager/apimanagement/2024-05-01/backend/method_workspacebackenddelete.go new file mode 100644 index 00000000000..8c7afcf5726 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/method_workspacebackenddelete.go @@ -0,0 +1,76 @@ +package backend + +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 WorkspaceBackendDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type WorkspaceBackendDeleteOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceBackendDeleteOperationOptions() WorkspaceBackendDeleteOperationOptions { + return WorkspaceBackendDeleteOperationOptions{} +} + +func (o WorkspaceBackendDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceBackendDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceBackendDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceBackendDelete ... +func (c BackendClient) WorkspaceBackendDelete(ctx context.Context, id WorkspaceBackendId, options WorkspaceBackendDeleteOperationOptions) (result WorkspaceBackendDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/method_workspacebackendget.go b/resource-manager/apimanagement/2024-05-01/backend/method_workspacebackendget.go new file mode 100644 index 00000000000..97fcb0925d5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/method_workspacebackendget.go @@ -0,0 +1,54 @@ +package backend + +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 WorkspaceBackendGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *BackendContract +} + +// WorkspaceBackendGet ... +func (c BackendClient) WorkspaceBackendGet(ctx context.Context, id WorkspaceBackendId) (result WorkspaceBackendGetOperationResponse, 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 BackendContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/method_workspacebackendgetentitytag.go b/resource-manager/apimanagement/2024-05-01/backend/method_workspacebackendgetentitytag.go new file mode 100644 index 00000000000..fd27ceec92c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/method_workspacebackendgetentitytag.go @@ -0,0 +1,46 @@ +package backend + +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 WorkspaceBackendGetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceBackendGetEntityTag ... +func (c BackendClient) WorkspaceBackendGetEntityTag(ctx context.Context, id WorkspaceBackendId) (result WorkspaceBackendGetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/method_workspacebackendlistbyworkspace.go b/resource-manager/apimanagement/2024-05-01/backend/method_workspacebackendlistbyworkspace.go new file mode 100644 index 00000000000..a762dc1a374 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/method_workspacebackendlistbyworkspace.go @@ -0,0 +1,141 @@ +package backend + +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 WorkspaceBackendListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]BackendContract +} + +type WorkspaceBackendListByWorkspaceCompleteResult struct { + LatestHttpResponse *http.Response + Items []BackendContract +} + +type WorkspaceBackendListByWorkspaceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultWorkspaceBackendListByWorkspaceOperationOptions() WorkspaceBackendListByWorkspaceOperationOptions { + return WorkspaceBackendListByWorkspaceOperationOptions{} +} + +func (o WorkspaceBackendListByWorkspaceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceBackendListByWorkspaceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceBackendListByWorkspaceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspaceBackendListByWorkspaceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceBackendListByWorkspaceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceBackendListByWorkspace ... +func (c BackendClient) WorkspaceBackendListByWorkspace(ctx context.Context, id WorkspaceId, options WorkspaceBackendListByWorkspaceOperationOptions) (result WorkspaceBackendListByWorkspaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspaceBackendListByWorkspaceCustomPager{}, + Path: fmt.Sprintf("%s/backends", 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 *[]BackendContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceBackendListByWorkspaceComplete retrieves all the results into a single object +func (c BackendClient) WorkspaceBackendListByWorkspaceComplete(ctx context.Context, id WorkspaceId, options WorkspaceBackendListByWorkspaceOperationOptions) (WorkspaceBackendListByWorkspaceCompleteResult, error) { + return c.WorkspaceBackendListByWorkspaceCompleteMatchingPredicate(ctx, id, options, BackendContractOperationPredicate{}) +} + +// WorkspaceBackendListByWorkspaceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BackendClient) WorkspaceBackendListByWorkspaceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options WorkspaceBackendListByWorkspaceOperationOptions, predicate BackendContractOperationPredicate) (result WorkspaceBackendListByWorkspaceCompleteResult, err error) { + items := make([]BackendContract, 0) + + resp, err := c.WorkspaceBackendListByWorkspace(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceBackendListByWorkspaceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/method_workspacebackendupdate.go b/resource-manager/apimanagement/2024-05-01/backend/method_workspacebackendupdate.go new file mode 100644 index 00000000000..5c4c93509de --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/method_workspacebackendupdate.go @@ -0,0 +1,87 @@ +package backend + +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 WorkspaceBackendUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *BackendContract +} + +type WorkspaceBackendUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceBackendUpdateOperationOptions() WorkspaceBackendUpdateOperationOptions { + return WorkspaceBackendUpdateOperationOptions{} +} + +func (o WorkspaceBackendUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceBackendUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceBackendUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceBackendUpdate ... +func (c BackendClient) WorkspaceBackendUpdate(ctx context.Context, id WorkspaceBackendId, input BackendUpdateParameters, options WorkspaceBackendUpdateOperationOptions) (result WorkspaceBackendUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 BackendContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/model_backendauthorizationheadercredentials.go b/resource-manager/apimanagement/2024-05-01/backend/model_backendauthorizationheadercredentials.go new file mode 100644 index 00000000000..dc87cc38a54 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/model_backendauthorizationheadercredentials.go @@ -0,0 +1,9 @@ +package backend + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackendAuthorizationHeaderCredentials struct { + Parameter string `json:"parameter"` + Scheme string `json:"scheme"` +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/model_backendbaseparameterspool.go b/resource-manager/apimanagement/2024-05-01/backend/model_backendbaseparameterspool.go new file mode 100644 index 00000000000..24e99e9c3e3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/model_backendbaseparameterspool.go @@ -0,0 +1,8 @@ +package backend + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackendBaseParametersPool struct { + Services *[]BackendPoolItem `json:"services,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/model_backendcircuitbreaker.go b/resource-manager/apimanagement/2024-05-01/backend/model_backendcircuitbreaker.go new file mode 100644 index 00000000000..519d6618931 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/model_backendcircuitbreaker.go @@ -0,0 +1,8 @@ +package backend + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackendCircuitBreaker struct { + Rules *[]CircuitBreakerRule `json:"rules,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/model_backendcontract.go b/resource-manager/apimanagement/2024-05-01/backend/model_backendcontract.go new file mode 100644 index 00000000000..b9b961e39e5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/model_backendcontract.go @@ -0,0 +1,11 @@ +package backend + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackendContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *BackendContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/model_backendcontractproperties.go b/resource-manager/apimanagement/2024-05-01/backend/model_backendcontractproperties.go new file mode 100644 index 00000000000..df63df7837f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/model_backendcontractproperties.go @@ -0,0 +1,19 @@ +package backend + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackendContractProperties struct { + CircuitBreaker *BackendCircuitBreaker `json:"circuitBreaker,omitempty"` + Credentials *BackendCredentialsContract `json:"credentials,omitempty"` + Description *string `json:"description,omitempty"` + Pool *BackendBaseParametersPool `json:"pool,omitempty"` + Properties *BackendProperties `json:"properties,omitempty"` + Protocol BackendProtocol `json:"protocol"` + Proxy *BackendProxyContract `json:"proxy,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` + Title *string `json:"title,omitempty"` + Tls *BackendTlsProperties `json:"tls,omitempty"` + Type *BackendType `json:"type,omitempty"` + Url string `json:"url"` +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/model_backendcredentialscontract.go b/resource-manager/apimanagement/2024-05-01/backend/model_backendcredentialscontract.go new file mode 100644 index 00000000000..6e825adfed9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/model_backendcredentialscontract.go @@ -0,0 +1,12 @@ +package backend + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackendCredentialsContract struct { + Authorization *BackendAuthorizationHeaderCredentials `json:"authorization,omitempty"` + Certificate *[]string `json:"certificate,omitempty"` + CertificateIds *[]string `json:"certificateIds,omitempty"` + Header *map[string][]string `json:"header,omitempty"` + Query *map[string][]string `json:"query,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/model_backendpoolitem.go b/resource-manager/apimanagement/2024-05-01/backend/model_backendpoolitem.go new file mode 100644 index 00000000000..338d2a42657 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/model_backendpoolitem.go @@ -0,0 +1,10 @@ +package backend + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackendPoolItem struct { + Id string `json:"id"` + Priority *int64 `json:"priority,omitempty"` + Weight *int64 `json:"weight,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/model_backendproperties.go b/resource-manager/apimanagement/2024-05-01/backend/model_backendproperties.go new file mode 100644 index 00000000000..5ac79552244 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/model_backendproperties.go @@ -0,0 +1,8 @@ +package backend + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackendProperties struct { + ServiceFabricCluster *BackendServiceFabricClusterProperties `json:"serviceFabricCluster,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/model_backendproxycontract.go b/resource-manager/apimanagement/2024-05-01/backend/model_backendproxycontract.go new file mode 100644 index 00000000000..7ba3d6bc958 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/model_backendproxycontract.go @@ -0,0 +1,10 @@ +package backend + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackendProxyContract struct { + Password *string `json:"password,omitempty"` + Url string `json:"url"` + Username *string `json:"username,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/model_backendservicefabricclusterproperties.go b/resource-manager/apimanagement/2024-05-01/backend/model_backendservicefabricclusterproperties.go new file mode 100644 index 00000000000..bc5eaf1b84c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/model_backendservicefabricclusterproperties.go @@ -0,0 +1,13 @@ +package backend + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackendServiceFabricClusterProperties struct { + ClientCertificateId *string `json:"clientCertificateId,omitempty"` + ClientCertificatethumbprint *string `json:"clientCertificatethumbprint,omitempty"` + ManagementEndpoints []string `json:"managementEndpoints"` + MaxPartitionResolutionRetries *int64 `json:"maxPartitionResolutionRetries,omitempty"` + ServerCertificateThumbprints *[]string `json:"serverCertificateThumbprints,omitempty"` + ServerX509Names *[]X509CertificateName `json:"serverX509Names,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/model_backendtlsproperties.go b/resource-manager/apimanagement/2024-05-01/backend/model_backendtlsproperties.go new file mode 100644 index 00000000000..740fde713b4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/model_backendtlsproperties.go @@ -0,0 +1,9 @@ +package backend + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackendTlsProperties struct { + ValidateCertificateChain *bool `json:"validateCertificateChain,omitempty"` + ValidateCertificateName *bool `json:"validateCertificateName,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/model_backendupdateparameterproperties.go b/resource-manager/apimanagement/2024-05-01/backend/model_backendupdateparameterproperties.go new file mode 100644 index 00000000000..c8bfe9b234f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/model_backendupdateparameterproperties.go @@ -0,0 +1,19 @@ +package backend + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackendUpdateParameterProperties struct { + CircuitBreaker *BackendCircuitBreaker `json:"circuitBreaker,omitempty"` + Credentials *BackendCredentialsContract `json:"credentials,omitempty"` + Description *string `json:"description,omitempty"` + Pool *BackendBaseParametersPool `json:"pool,omitempty"` + Properties *BackendProperties `json:"properties,omitempty"` + Protocol *BackendProtocol `json:"protocol,omitempty"` + Proxy *BackendProxyContract `json:"proxy,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` + Title *string `json:"title,omitempty"` + Tls *BackendTlsProperties `json:"tls,omitempty"` + Type *BackendType `json:"type,omitempty"` + Url *string `json:"url,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/model_backendupdateparameters.go b/resource-manager/apimanagement/2024-05-01/backend/model_backendupdateparameters.go new file mode 100644 index 00000000000..dfaa01193d2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/model_backendupdateparameters.go @@ -0,0 +1,8 @@ +package backend + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackendUpdateParameters struct { + Properties *BackendUpdateParameterProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/model_circuitbreakerfailurecondition.go b/resource-manager/apimanagement/2024-05-01/backend/model_circuitbreakerfailurecondition.go new file mode 100644 index 00000000000..4bf225da9b5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/model_circuitbreakerfailurecondition.go @@ -0,0 +1,12 @@ +package backend + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CircuitBreakerFailureCondition struct { + Count *int64 `json:"count,omitempty"` + ErrorReasons *[]string `json:"errorReasons,omitempty"` + Interval *string `json:"interval,omitempty"` + Percentage *int64 `json:"percentage,omitempty"` + StatusCodeRanges *[]FailureStatusCodeRange `json:"statusCodeRanges,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/model_circuitbreakerrule.go b/resource-manager/apimanagement/2024-05-01/backend/model_circuitbreakerrule.go new file mode 100644 index 00000000000..c6356eff915 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/model_circuitbreakerrule.go @@ -0,0 +1,11 @@ +package backend + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CircuitBreakerRule struct { + AcceptRetryAfter *bool `json:"acceptRetryAfter,omitempty"` + FailureCondition *CircuitBreakerFailureCondition `json:"failureCondition,omitempty"` + Name *string `json:"name,omitempty"` + TripDuration *string `json:"tripDuration,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/model_failurestatuscoderange.go b/resource-manager/apimanagement/2024-05-01/backend/model_failurestatuscoderange.go new file mode 100644 index 00000000000..785441b644b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/model_failurestatuscoderange.go @@ -0,0 +1,9 @@ +package backend + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FailureStatusCodeRange struct { + Max *int64 `json:"max,omitempty"` + Min *int64 `json:"min,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/model_x509certificatename.go b/resource-manager/apimanagement/2024-05-01/backend/model_x509certificatename.go new file mode 100644 index 00000000000..12faade510c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/model_x509certificatename.go @@ -0,0 +1,9 @@ +package backend + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type X509CertificateName struct { + IssuerCertificateThumbprint *string `json:"issuerCertificateThumbprint,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/backend/predicates.go b/resource-manager/apimanagement/2024-05-01/backend/predicates.go new file mode 100644 index 00000000000..42bc6a1a63f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/predicates.go @@ -0,0 +1,27 @@ +package backend + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackendContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p BackendContractOperationPredicate) Matches(input BackendContract) 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/apimanagement/2024-05-01/backend/version.go b/resource-manager/apimanagement/2024-05-01/backend/version.go new file mode 100644 index 00000000000..483eb99ac9e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backend/version.go @@ -0,0 +1,12 @@ +package backend + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/backend/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/backendreconnect/README.md b/resource-manager/apimanagement/2024-05-01/backendreconnect/README.md new file mode 100644 index 00000000000..fecad7c8a22 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backendreconnect/README.md @@ -0,0 +1,41 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/backendreconnect` Documentation + +The `backendreconnect` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/backendreconnect" +``` + + +### Client Initialization + +```go +client := backendreconnect.NewBackendReconnectClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackendReconnectClient.BackendReconnect` + +```go +ctx := context.TODO() +id := backendreconnect.NewBackendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "backendIdValue") + +payload := backendreconnect.BackendReconnectContract{ + // ... +} + + +read, err := client.BackendReconnect(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/apimanagement/2024-05-01/backendreconnect/client.go b/resource-manager/apimanagement/2024-05-01/backendreconnect/client.go new file mode 100644 index 00000000000..e7931af1711 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backendreconnect/client.go @@ -0,0 +1,26 @@ +package backendreconnect + +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 BackendReconnectClient struct { + Client *resourcemanager.Client +} + +func NewBackendReconnectClientWithBaseURI(sdkApi sdkEnv.Api) (*BackendReconnectClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "backendreconnect", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BackendReconnectClient: %+v", err) + } + + return &BackendReconnectClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/backendreconnect/id_backend.go b/resource-manager/apimanagement/2024-05-01/backendreconnect/id_backend.go new file mode 100644 index 00000000000..8099482517f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backendreconnect/id_backend.go @@ -0,0 +1,139 @@ +package backendreconnect + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BackendId{}) +} + +var _ resourceids.ResourceId = &BackendId{} + +// BackendId is a struct representing the Resource ID for a Backend +type BackendId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + BackendId string +} + +// NewBackendID returns a new BackendId struct +func NewBackendID(subscriptionId string, resourceGroupName string, serviceName string, backendId string) BackendId { + return BackendId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + BackendId: backendId, + } +} + +// ParseBackendID parses 'input' into a BackendId +func ParseBackendID(input string) (*BackendId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackendId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackendId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackendIDInsensitively parses 'input' case-insensitively into a BackendId +// note: this method should only be used for API response data and not user input +func ParseBackendIDInsensitively(input string) (*BackendId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackendId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackendId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackendId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.BackendId, ok = input.Parsed["backendId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backendId", input) + } + + return nil +} + +// ValidateBackendID checks that 'input' can be parsed as a Backend ID +func ValidateBackendID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseBackendID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backend ID +func (id BackendId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/backends/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.BackendId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backend ID +func (id BackendId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticBackends", "backends", "backends"), + resourceids.UserSpecifiedSegment("backendId", "backendIdValue"), + } +} + +// String returns a human-readable description of this Backend ID +func (id BackendId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Backend: %q", id.BackendId), + } + return fmt.Sprintf("Backend (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/backendreconnect/id_backend_test.go b/resource-manager/apimanagement/2024-05-01/backendreconnect/id_backend_test.go new file mode 100644 index 00000000000..9de7d297190 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backendreconnect/id_backend_test.go @@ -0,0 +1,327 @@ +package backendreconnect + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &BackendId{} + +func TestNewBackendID(t *testing.T) { + id := NewBackendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "backendIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.BackendId != "backendIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'BackendId'", id.BackendId, "backendIdValue") + } +} + +func TestFormatBackendID(t *testing.T) { + actual := NewBackendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "backendIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/backends/backendIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackendID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackendId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/backends", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/backends/backendIdValue", + Expected: &BackendId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + BackendId: "backendIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/backends/backendIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackendID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.BackendId != v.Expected.BackendId { + t.Fatalf("Expected %q but got %q for BackendId", v.Expected.BackendId, actual.BackendId) + } + + } +} + +func TestParseBackendIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackendId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/backends", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/bAcKeNdS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/backends/backendIdValue", + Expected: &BackendId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + BackendId: "backendIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/backends/backendIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/bAcKeNdS/bAcKeNdIdVaLuE", + Expected: &BackendId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + BackendId: "bAcKeNdIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/bAcKeNdS/bAcKeNdIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackendIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.BackendId != v.Expected.BackendId { + t.Fatalf("Expected %q but got %q for BackendId", v.Expected.BackendId, actual.BackendId) + } + + } +} + +func TestSegmentsForBackendId(t *testing.T) { + segments := BackendId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackendId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/backendreconnect/method_backendreconnect.go b/resource-manager/apimanagement/2024-05-01/backendreconnect/method_backendreconnect.go new file mode 100644 index 00000000000..d75c5992fac --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backendreconnect/method_backendreconnect.go @@ -0,0 +1,51 @@ +package backendreconnect + +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 BackendReconnectOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// BackendReconnect ... +func (c BackendReconnectClient) BackendReconnect(ctx context.Context, id BackendId, input BackendReconnectContract) (result BackendReconnectOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/reconnect", 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/apimanagement/2024-05-01/backendreconnect/model_backendreconnectcontract.go b/resource-manager/apimanagement/2024-05-01/backendreconnect/model_backendreconnectcontract.go new file mode 100644 index 00000000000..1b91259c5b7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backendreconnect/model_backendreconnectcontract.go @@ -0,0 +1,11 @@ +package backendreconnect + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackendReconnectContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *BackendReconnectProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/backendreconnect/model_backendreconnectproperties.go b/resource-manager/apimanagement/2024-05-01/backendreconnect/model_backendreconnectproperties.go new file mode 100644 index 00000000000..d22eb4fc061 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backendreconnect/model_backendreconnectproperties.go @@ -0,0 +1,8 @@ +package backendreconnect + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackendReconnectProperties struct { + After *string `json:"after,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/backendreconnect/version.go b/resource-manager/apimanagement/2024-05-01/backendreconnect/version.go new file mode 100644 index 00000000000..e3ca3e180c6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/backendreconnect/version.go @@ -0,0 +1,12 @@ +package backendreconnect + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/backendreconnect/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/cache/README.md b/resource-manager/apimanagement/2024-05-01/cache/README.md new file mode 100644 index 00000000000..892f314f8de --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/cache/README.md @@ -0,0 +1,127 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/cache` Documentation + +The `cache` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/cache" +``` + + +### Client Initialization + +```go +client := cache.NewCacheClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `CacheClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := cache.NewCacheID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "cacheIdValue") + +payload := cache.CacheContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, cache.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CacheClient.Delete` + +```go +ctx := context.TODO() +id := cache.NewCacheID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "cacheIdValue") + +read, err := client.Delete(ctx, id, cache.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CacheClient.Get` + +```go +ctx := context.TODO() +id := cache.NewCacheID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "cacheIdValue") + +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: `CacheClient.GetEntityTag` + +```go +ctx := context.TODO() +id := cache.NewCacheID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "cacheIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CacheClient.ListByService` + +```go +ctx := context.TODO() +id := cache.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, cache.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, cache.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `CacheClient.Update` + +```go +ctx := context.TODO() +id := cache.NewCacheID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "cacheIdValue") + +payload := cache.CacheUpdateParameters{ + // ... +} + + +read, err := client.Update(ctx, id, payload, cache.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/cache/client.go b/resource-manager/apimanagement/2024-05-01/cache/client.go new file mode 100644 index 00000000000..e0befe22fa3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/cache/client.go @@ -0,0 +1,26 @@ +package cache + +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 CacheClient struct { + Client *resourcemanager.Client +} + +func NewCacheClientWithBaseURI(sdkApi sdkEnv.Api) (*CacheClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "cache", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CacheClient: %+v", err) + } + + return &CacheClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/cache/id_cache.go b/resource-manager/apimanagement/2024-05-01/cache/id_cache.go new file mode 100644 index 00000000000..8260234796a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/cache/id_cache.go @@ -0,0 +1,139 @@ +package cache + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&CacheId{}) +} + +var _ resourceids.ResourceId = &CacheId{} + +// CacheId is a struct representing the Resource ID for a Cache +type CacheId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + CacheId string +} + +// NewCacheID returns a new CacheId struct +func NewCacheID(subscriptionId string, resourceGroupName string, serviceName string, cacheId string) CacheId { + return CacheId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + CacheId: cacheId, + } +} + +// ParseCacheID parses 'input' into a CacheId +func ParseCacheID(input string) (*CacheId, error) { + parser := resourceids.NewParserFromResourceIdType(&CacheId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CacheId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseCacheIDInsensitively parses 'input' case-insensitively into a CacheId +// note: this method should only be used for API response data and not user input +func ParseCacheIDInsensitively(input string) (*CacheId, error) { + parser := resourceids.NewParserFromResourceIdType(&CacheId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CacheId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *CacheId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.CacheId, ok = input.Parsed["cacheId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "cacheId", input) + } + + return nil +} + +// ValidateCacheID checks that 'input' can be parsed as a Cache ID +func ValidateCacheID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseCacheID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Cache ID +func (id CacheId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/caches/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.CacheId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Cache ID +func (id CacheId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticCaches", "caches", "caches"), + resourceids.UserSpecifiedSegment("cacheId", "cacheIdValue"), + } +} + +// String returns a human-readable description of this Cache ID +func (id CacheId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Cache: %q", id.CacheId), + } + return fmt.Sprintf("Cache (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/cache/id_cache_test.go b/resource-manager/apimanagement/2024-05-01/cache/id_cache_test.go new file mode 100644 index 00000000000..c2476a2f3dc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/cache/id_cache_test.go @@ -0,0 +1,327 @@ +package cache + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &CacheId{} + +func TestNewCacheID(t *testing.T) { + id := NewCacheID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "cacheIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.CacheId != "cacheIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'CacheId'", id.CacheId, "cacheIdValue") + } +} + +func TestFormatCacheID(t *testing.T) { + actual := NewCacheID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "cacheIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/caches/cacheIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCacheID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CacheId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/caches", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/caches/cacheIdValue", + Expected: &CacheId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + CacheId: "cacheIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/caches/cacheIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCacheID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.CacheId != v.Expected.CacheId { + t.Fatalf("Expected %q but got %q for CacheId", v.Expected.CacheId, actual.CacheId) + } + + } +} + +func TestParseCacheIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CacheId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/caches", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/cAcHeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/caches/cacheIdValue", + Expected: &CacheId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + CacheId: "cacheIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/caches/cacheIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/cAcHeS/cAcHeIdVaLuE", + Expected: &CacheId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + CacheId: "cAcHeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/cAcHeS/cAcHeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCacheIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.CacheId != v.Expected.CacheId { + t.Fatalf("Expected %q but got %q for CacheId", v.Expected.CacheId, actual.CacheId) + } + + } +} + +func TestSegmentsForCacheId(t *testing.T) { + segments := CacheId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CacheId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/cache/id_service.go b/resource-manager/apimanagement/2024-05-01/cache/id_service.go new file mode 100644 index 00000000000..bf4f26d8b36 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/cache/id_service.go @@ -0,0 +1,130 @@ +package cache + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/cache/id_service_test.go b/resource-manager/apimanagement/2024-05-01/cache/id_service_test.go new file mode 100644 index 00000000000..8ffab39c330 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/cache/id_service_test.go @@ -0,0 +1,282 @@ +package cache + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/cache/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/cache/method_createorupdate.go new file mode 100644 index 00000000000..26ef5edfcc7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/cache/method_createorupdate.go @@ -0,0 +1,88 @@ +package cache + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CacheContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c CacheClient) CreateOrUpdate(ctx context.Context, id CacheId, input CacheContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 CacheContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/cache/method_delete.go b/resource-manager/apimanagement/2024-05-01/cache/method_delete.go new file mode 100644 index 00000000000..511791374c6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/cache/method_delete.go @@ -0,0 +1,76 @@ +package cache + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c CacheClient) Delete(ctx context.Context, id CacheId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/cache/method_get.go b/resource-manager/apimanagement/2024-05-01/cache/method_get.go new file mode 100644 index 00000000000..10fd3d603ea --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/cache/method_get.go @@ -0,0 +1,54 @@ +package cache + +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 *CacheContract +} + +// Get ... +func (c CacheClient) Get(ctx context.Context, id CacheId) (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 CacheContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/cache/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/cache/method_getentitytag.go new file mode 100644 index 00000000000..a221bde18d1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/cache/method_getentitytag.go @@ -0,0 +1,46 @@ +package cache + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c CacheClient) GetEntityTag(ctx context.Context, id CacheId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/cache/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/cache/method_listbyservice.go new file mode 100644 index 00000000000..29189620638 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/cache/method_listbyservice.go @@ -0,0 +1,137 @@ +package cache + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]CacheContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []CacheContract +} + +type ListByServiceOperationOptions struct { + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c CacheClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/caches", 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 *[]CacheContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c CacheClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, CacheContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CacheClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate CacheContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]CacheContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/cache/method_update.go b/resource-manager/apimanagement/2024-05-01/cache/method_update.go new file mode 100644 index 00000000000..9388cab550d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/cache/method_update.go @@ -0,0 +1,87 @@ +package cache + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CacheContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c CacheClient) Update(ctx context.Context, id CacheId, input CacheUpdateParameters, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 CacheContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/cache/model_cachecontract.go b/resource-manager/apimanagement/2024-05-01/cache/model_cachecontract.go new file mode 100644 index 00000000000..6ce21934bcd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/cache/model_cachecontract.go @@ -0,0 +1,11 @@ +package cache + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CacheContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *CacheContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/cache/model_cachecontractproperties.go b/resource-manager/apimanagement/2024-05-01/cache/model_cachecontractproperties.go new file mode 100644 index 00000000000..930e9155fab --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/cache/model_cachecontractproperties.go @@ -0,0 +1,11 @@ +package cache + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CacheContractProperties struct { + ConnectionString string `json:"connectionString"` + Description *string `json:"description,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` + UseFromLocation string `json:"useFromLocation"` +} diff --git a/resource-manager/apimanagement/2024-05-01/cache/model_cacheupdateparameters.go b/resource-manager/apimanagement/2024-05-01/cache/model_cacheupdateparameters.go new file mode 100644 index 00000000000..6519a6e4c7e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/cache/model_cacheupdateparameters.go @@ -0,0 +1,8 @@ +package cache + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CacheUpdateParameters struct { + Properties *CacheUpdateProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/cache/model_cacheupdateproperties.go b/resource-manager/apimanagement/2024-05-01/cache/model_cacheupdateproperties.go new file mode 100644 index 00000000000..3e8292d3f83 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/cache/model_cacheupdateproperties.go @@ -0,0 +1,11 @@ +package cache + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CacheUpdateProperties struct { + ConnectionString *string `json:"connectionString,omitempty"` + Description *string `json:"description,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` + UseFromLocation *string `json:"useFromLocation,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/cache/predicates.go b/resource-manager/apimanagement/2024-05-01/cache/predicates.go new file mode 100644 index 00000000000..e1d595e6530 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/cache/predicates.go @@ -0,0 +1,27 @@ +package cache + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CacheContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p CacheContractOperationPredicate) Matches(input CacheContract) 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/apimanagement/2024-05-01/cache/version.go b/resource-manager/apimanagement/2024-05-01/cache/version.go new file mode 100644 index 00000000000..abeb3a30a95 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/cache/version.go @@ -0,0 +1,12 @@ +package cache + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/cache/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/README.md b/resource-manager/apimanagement/2024-05-01/certificate/README.md new file mode 100644 index 00000000000..b3dbed27310 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/README.md @@ -0,0 +1,224 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/certificate` Documentation + +The `certificate` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/certificate" +``` + + +### Client Initialization + +```go +client := certificate.NewCertificateClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `CertificateClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := certificate.NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "certificateIdValue") + +payload := certificate.CertificateCreateOrUpdateParameters{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, certificate.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CertificateClient.Delete` + +```go +ctx := context.TODO() +id := certificate.NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "certificateIdValue") + +read, err := client.Delete(ctx, id, certificate.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CertificateClient.Get` + +```go +ctx := context.TODO() +id := certificate.NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "certificateIdValue") + +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: `CertificateClient.GetEntityTag` + +```go +ctx := context.TODO() +id := certificate.NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "certificateIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CertificateClient.ListByService` + +```go +ctx := context.TODO() +id := certificate.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, certificate.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, certificate.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `CertificateClient.RefreshSecret` + +```go +ctx := context.TODO() +id := certificate.NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "certificateIdValue") + +read, err := client.RefreshSecret(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CertificateClient.WorkspaceCertificateCreateOrUpdate` + +```go +ctx := context.TODO() +id := certificate.NewWorkspaceCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "certificateIdValue") + +payload := certificate.CertificateCreateOrUpdateParameters{ + // ... +} + + +read, err := client.WorkspaceCertificateCreateOrUpdate(ctx, id, payload, certificate.DefaultWorkspaceCertificateCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CertificateClient.WorkspaceCertificateDelete` + +```go +ctx := context.TODO() +id := certificate.NewWorkspaceCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "certificateIdValue") + +read, err := client.WorkspaceCertificateDelete(ctx, id, certificate.DefaultWorkspaceCertificateDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CertificateClient.WorkspaceCertificateGet` + +```go +ctx := context.TODO() +id := certificate.NewWorkspaceCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "certificateIdValue") + +read, err := client.WorkspaceCertificateGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CertificateClient.WorkspaceCertificateGetEntityTag` + +```go +ctx := context.TODO() +id := certificate.NewWorkspaceCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "certificateIdValue") + +read, err := client.WorkspaceCertificateGetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CertificateClient.WorkspaceCertificateListByWorkspace` + +```go +ctx := context.TODO() +id := certificate.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +// alternatively `client.WorkspaceCertificateListByWorkspace(ctx, id, certificate.DefaultWorkspaceCertificateListByWorkspaceOperationOptions())` can be used to do batched pagination +items, err := client.WorkspaceCertificateListByWorkspaceComplete(ctx, id, certificate.DefaultWorkspaceCertificateListByWorkspaceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `CertificateClient.WorkspaceCertificateRefreshSecret` + +```go +ctx := context.TODO() +id := certificate.NewWorkspaceCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "certificateIdValue") + +read, err := client.WorkspaceCertificateRefreshSecret(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/apimanagement/2024-05-01/certificate/client.go b/resource-manager/apimanagement/2024-05-01/certificate/client.go new file mode 100644 index 00000000000..9c7a6885362 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/client.go @@ -0,0 +1,26 @@ +package certificate + +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 CertificateClient struct { + Client *resourcemanager.Client +} + +func NewCertificateClientWithBaseURI(sdkApi sdkEnv.Api) (*CertificateClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "certificate", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CertificateClient: %+v", err) + } + + return &CertificateClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/id_certificate.go b/resource-manager/apimanagement/2024-05-01/certificate/id_certificate.go new file mode 100644 index 00000000000..8617e21ad2a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/id_certificate.go @@ -0,0 +1,139 @@ +package certificate + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&CertificateId{}) +} + +var _ resourceids.ResourceId = &CertificateId{} + +// CertificateId is a struct representing the Resource ID for a Certificate +type CertificateId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + CertificateId string +} + +// NewCertificateID returns a new CertificateId struct +func NewCertificateID(subscriptionId string, resourceGroupName string, serviceName string, certificateId string) CertificateId { + return CertificateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + CertificateId: certificateId, + } +} + +// ParseCertificateID parses 'input' into a CertificateId +func ParseCertificateID(input string) (*CertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(&CertificateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CertificateId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseCertificateIDInsensitively parses 'input' case-insensitively into a CertificateId +// note: this method should only be used for API response data and not user input +func ParseCertificateIDInsensitively(input string) (*CertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(&CertificateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CertificateId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *CertificateId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.CertificateId, ok = input.Parsed["certificateId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "certificateId", input) + } + + return nil +} + +// ValidateCertificateID checks that 'input' can be parsed as a Certificate ID +func ValidateCertificateID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseCertificateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Certificate ID +func (id CertificateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/certificates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.CertificateId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Certificate ID +func (id CertificateId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticCertificates", "certificates", "certificates"), + resourceids.UserSpecifiedSegment("certificateId", "certificateIdValue"), + } +} + +// String returns a human-readable description of this Certificate ID +func (id CertificateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Certificate: %q", id.CertificateId), + } + return fmt.Sprintf("Certificate (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/id_certificate_test.go b/resource-manager/apimanagement/2024-05-01/certificate/id_certificate_test.go new file mode 100644 index 00000000000..2a65007be1b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/id_certificate_test.go @@ -0,0 +1,327 @@ +package certificate + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &CertificateId{} + +func TestNewCertificateID(t *testing.T) { + id := NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "certificateIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.CertificateId != "certificateIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'CertificateId'", id.CertificateId, "certificateIdValue") + } +} + +func TestFormatCertificateID(t *testing.T) { + actual := NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "certificateIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/certificates/certificateIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCertificateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CertificateId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/certificates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/certificates/certificateIdValue", + Expected: &CertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + CertificateId: "certificateIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/certificates/certificateIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCertificateID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.CertificateId != v.Expected.CertificateId { + t.Fatalf("Expected %q but got %q for CertificateId", v.Expected.CertificateId, actual.CertificateId) + } + + } +} + +func TestParseCertificateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CertificateId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/certificates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/cErTiFiCaTeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/certificates/certificateIdValue", + Expected: &CertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + CertificateId: "certificateIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/certificates/certificateIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/cErTiFiCaTeS/cErTiFiCaTeIdVaLuE", + Expected: &CertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + CertificateId: "cErTiFiCaTeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/cErTiFiCaTeS/cErTiFiCaTeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCertificateIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.CertificateId != v.Expected.CertificateId { + t.Fatalf("Expected %q but got %q for CertificateId", v.Expected.CertificateId, actual.CertificateId) + } + + } +} + +func TestSegmentsForCertificateId(t *testing.T) { + segments := CertificateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CertificateId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/id_service.go b/resource-manager/apimanagement/2024-05-01/certificate/id_service.go new file mode 100644 index 00000000000..75f9ac3b04b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/id_service.go @@ -0,0 +1,130 @@ +package certificate + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/id_service_test.go b/resource-manager/apimanagement/2024-05-01/certificate/id_service_test.go new file mode 100644 index 00000000000..456ab2758c1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/id_service_test.go @@ -0,0 +1,282 @@ +package certificate + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/id_workspace.go b/resource-manager/apimanagement/2024-05-01/certificate/id_workspace.go new file mode 100644 index 00000000000..f0e6c933422 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/id_workspace.go @@ -0,0 +1,139 @@ +package certificate + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/id_workspace_test.go b/resource-manager/apimanagement/2024-05-01/certificate/id_workspace_test.go new file mode 100644 index 00000000000..45df4da91b5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/id_workspace_test.go @@ -0,0 +1,327 @@ +package certificate + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/id_workspacecertificate.go b/resource-manager/apimanagement/2024-05-01/certificate/id_workspacecertificate.go new file mode 100644 index 00000000000..08e1c29327d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/id_workspacecertificate.go @@ -0,0 +1,148 @@ +package certificate + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceCertificateId{}) +} + +var _ resourceids.ResourceId = &WorkspaceCertificateId{} + +// WorkspaceCertificateId is a struct representing the Resource ID for a Workspace Certificate +type WorkspaceCertificateId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + CertificateId string +} + +// NewWorkspaceCertificateID returns a new WorkspaceCertificateId struct +func NewWorkspaceCertificateID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, certificateId string) WorkspaceCertificateId { + return WorkspaceCertificateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + CertificateId: certificateId, + } +} + +// ParseWorkspaceCertificateID parses 'input' into a WorkspaceCertificateId +func ParseWorkspaceCertificateID(input string) (*WorkspaceCertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceCertificateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceCertificateId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceCertificateIDInsensitively parses 'input' case-insensitively into a WorkspaceCertificateId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceCertificateIDInsensitively(input string) (*WorkspaceCertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceCertificateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceCertificateId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceCertificateId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.CertificateId, ok = input.Parsed["certificateId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "certificateId", input) + } + + return nil +} + +// ValidateWorkspaceCertificateID checks that 'input' can be parsed as a Workspace Certificate ID +func ValidateWorkspaceCertificateID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceCertificateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Certificate ID +func (id WorkspaceCertificateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/certificates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.CertificateId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Certificate ID +func (id WorkspaceCertificateId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticCertificates", "certificates", "certificates"), + resourceids.UserSpecifiedSegment("certificateId", "certificateIdValue"), + } +} + +// String returns a human-readable description of this Workspace Certificate ID +func (id WorkspaceCertificateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Certificate: %q", id.CertificateId), + } + return fmt.Sprintf("Workspace Certificate (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/id_workspacecertificate_test.go b/resource-manager/apimanagement/2024-05-01/certificate/id_workspacecertificate_test.go new file mode 100644 index 00000000000..2c2b380d319 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/id_workspacecertificate_test.go @@ -0,0 +1,372 @@ +package certificate + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceCertificateId{} + +func TestNewWorkspaceCertificateID(t *testing.T) { + id := NewWorkspaceCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "certificateIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.CertificateId != "certificateIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'CertificateId'", id.CertificateId, "certificateIdValue") + } +} + +func TestFormatWorkspaceCertificateID(t *testing.T) { + actual := NewWorkspaceCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "certificateIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/certificates/certificateIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceCertificateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceCertificateId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/certificates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/certificates/certificateIdValue", + Expected: &WorkspaceCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + CertificateId: "certificateIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/certificates/certificateIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceCertificateID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.CertificateId != v.Expected.CertificateId { + t.Fatalf("Expected %q but got %q for CertificateId", v.Expected.CertificateId, actual.CertificateId) + } + + } +} + +func TestParseWorkspaceCertificateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceCertificateId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/certificates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/cErTiFiCaTeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/certificates/certificateIdValue", + Expected: &WorkspaceCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + CertificateId: "certificateIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/certificates/certificateIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/cErTiFiCaTeS/cErTiFiCaTeIdVaLuE", + Expected: &WorkspaceCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + CertificateId: "cErTiFiCaTeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/cErTiFiCaTeS/cErTiFiCaTeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceCertificateIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.CertificateId != v.Expected.CertificateId { + t.Fatalf("Expected %q but got %q for CertificateId", v.Expected.CertificateId, actual.CertificateId) + } + + } +} + +func TestSegmentsForWorkspaceCertificateId(t *testing.T) { + segments := WorkspaceCertificateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceCertificateId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/certificate/method_createorupdate.go new file mode 100644 index 00000000000..823d71d3e64 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/method_createorupdate.go @@ -0,0 +1,88 @@ +package certificate + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CertificateContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c CertificateClient) CreateOrUpdate(ctx context.Context, id CertificateId, input CertificateCreateOrUpdateParameters, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 CertificateContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/method_delete.go b/resource-manager/apimanagement/2024-05-01/certificate/method_delete.go new file mode 100644 index 00000000000..6c0ded0942d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/method_delete.go @@ -0,0 +1,76 @@ +package certificate + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c CertificateClient) Delete(ctx context.Context, id CertificateId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/method_get.go b/resource-manager/apimanagement/2024-05-01/certificate/method_get.go new file mode 100644 index 00000000000..884851fd83b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/method_get.go @@ -0,0 +1,54 @@ +package certificate + +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 *CertificateContract +} + +// Get ... +func (c CertificateClient) Get(ctx context.Context, id CertificateId) (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 CertificateContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/certificate/method_getentitytag.go new file mode 100644 index 00000000000..bcbd65b8f9b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/method_getentitytag.go @@ -0,0 +1,46 @@ +package certificate + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c CertificateClient) GetEntityTag(ctx context.Context, id CertificateId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/certificate/method_listbyservice.go new file mode 100644 index 00000000000..9f45a52fd7c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/method_listbyservice.go @@ -0,0 +1,145 @@ +package certificate + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]CertificateContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []CertificateContract +} + +type ListByServiceOperationOptions struct { + Filter *string + IsKeyVaultRefreshFailed *bool + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.IsKeyVaultRefreshFailed != nil { + out.Append("isKeyVaultRefreshFailed", fmt.Sprintf("%v", *o.IsKeyVaultRefreshFailed)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c CertificateClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/certificates", 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 *[]CertificateContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c CertificateClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, CertificateContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CertificateClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate CertificateContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]CertificateContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/method_refreshsecret.go b/resource-manager/apimanagement/2024-05-01/certificate/method_refreshsecret.go new file mode 100644 index 00000000000..d764ec89d26 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/method_refreshsecret.go @@ -0,0 +1,55 @@ +package certificate + +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 RefreshSecretOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CertificateContract +} + +// RefreshSecret ... +func (c CertificateClient) RefreshSecret(ctx context.Context, id CertificateId) (result RefreshSecretOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/refreshSecret", 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 CertificateContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/method_workspacecertificatecreateorupdate.go b/resource-manager/apimanagement/2024-05-01/certificate/method_workspacecertificatecreateorupdate.go new file mode 100644 index 00000000000..edf3cac36ce --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/method_workspacecertificatecreateorupdate.go @@ -0,0 +1,88 @@ +package certificate + +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 WorkspaceCertificateCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CertificateContract +} + +type WorkspaceCertificateCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceCertificateCreateOrUpdateOperationOptions() WorkspaceCertificateCreateOrUpdateOperationOptions { + return WorkspaceCertificateCreateOrUpdateOperationOptions{} +} + +func (o WorkspaceCertificateCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceCertificateCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceCertificateCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceCertificateCreateOrUpdate ... +func (c CertificateClient) WorkspaceCertificateCreateOrUpdate(ctx context.Context, id WorkspaceCertificateId, input CertificateCreateOrUpdateParameters, options WorkspaceCertificateCreateOrUpdateOperationOptions) (result WorkspaceCertificateCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 CertificateContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/method_workspacecertificatedelete.go b/resource-manager/apimanagement/2024-05-01/certificate/method_workspacecertificatedelete.go new file mode 100644 index 00000000000..f100d30f114 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/method_workspacecertificatedelete.go @@ -0,0 +1,76 @@ +package certificate + +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 WorkspaceCertificateDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type WorkspaceCertificateDeleteOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceCertificateDeleteOperationOptions() WorkspaceCertificateDeleteOperationOptions { + return WorkspaceCertificateDeleteOperationOptions{} +} + +func (o WorkspaceCertificateDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceCertificateDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceCertificateDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceCertificateDelete ... +func (c CertificateClient) WorkspaceCertificateDelete(ctx context.Context, id WorkspaceCertificateId, options WorkspaceCertificateDeleteOperationOptions) (result WorkspaceCertificateDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/method_workspacecertificateget.go b/resource-manager/apimanagement/2024-05-01/certificate/method_workspacecertificateget.go new file mode 100644 index 00000000000..db76a610302 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/method_workspacecertificateget.go @@ -0,0 +1,54 @@ +package certificate + +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 WorkspaceCertificateGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CertificateContract +} + +// WorkspaceCertificateGet ... +func (c CertificateClient) WorkspaceCertificateGet(ctx context.Context, id WorkspaceCertificateId) (result WorkspaceCertificateGetOperationResponse, 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 CertificateContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/method_workspacecertificategetentitytag.go b/resource-manager/apimanagement/2024-05-01/certificate/method_workspacecertificategetentitytag.go new file mode 100644 index 00000000000..275fe34b69b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/method_workspacecertificategetentitytag.go @@ -0,0 +1,46 @@ +package certificate + +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 WorkspaceCertificateGetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceCertificateGetEntityTag ... +func (c CertificateClient) WorkspaceCertificateGetEntityTag(ctx context.Context, id WorkspaceCertificateId) (result WorkspaceCertificateGetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/method_workspacecertificatelistbyworkspace.go b/resource-manager/apimanagement/2024-05-01/certificate/method_workspacecertificatelistbyworkspace.go new file mode 100644 index 00000000000..c2931b1c245 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/method_workspacecertificatelistbyworkspace.go @@ -0,0 +1,145 @@ +package certificate + +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 WorkspaceCertificateListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]CertificateContract +} + +type WorkspaceCertificateListByWorkspaceCompleteResult struct { + LatestHttpResponse *http.Response + Items []CertificateContract +} + +type WorkspaceCertificateListByWorkspaceOperationOptions struct { + Filter *string + IsKeyVaultRefreshFailed *bool + Skip *int64 + Top *int64 +} + +func DefaultWorkspaceCertificateListByWorkspaceOperationOptions() WorkspaceCertificateListByWorkspaceOperationOptions { + return WorkspaceCertificateListByWorkspaceOperationOptions{} +} + +func (o WorkspaceCertificateListByWorkspaceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceCertificateListByWorkspaceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceCertificateListByWorkspaceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.IsKeyVaultRefreshFailed != nil { + out.Append("isKeyVaultRefreshFailed", fmt.Sprintf("%v", *o.IsKeyVaultRefreshFailed)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspaceCertificateListByWorkspaceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceCertificateListByWorkspaceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceCertificateListByWorkspace ... +func (c CertificateClient) WorkspaceCertificateListByWorkspace(ctx context.Context, id WorkspaceId, options WorkspaceCertificateListByWorkspaceOperationOptions) (result WorkspaceCertificateListByWorkspaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspaceCertificateListByWorkspaceCustomPager{}, + Path: fmt.Sprintf("%s/certificates", 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 *[]CertificateContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceCertificateListByWorkspaceComplete retrieves all the results into a single object +func (c CertificateClient) WorkspaceCertificateListByWorkspaceComplete(ctx context.Context, id WorkspaceId, options WorkspaceCertificateListByWorkspaceOperationOptions) (WorkspaceCertificateListByWorkspaceCompleteResult, error) { + return c.WorkspaceCertificateListByWorkspaceCompleteMatchingPredicate(ctx, id, options, CertificateContractOperationPredicate{}) +} + +// WorkspaceCertificateListByWorkspaceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CertificateClient) WorkspaceCertificateListByWorkspaceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options WorkspaceCertificateListByWorkspaceOperationOptions, predicate CertificateContractOperationPredicate) (result WorkspaceCertificateListByWorkspaceCompleteResult, err error) { + items := make([]CertificateContract, 0) + + resp, err := c.WorkspaceCertificateListByWorkspace(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceCertificateListByWorkspaceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/method_workspacecertificaterefreshsecret.go b/resource-manager/apimanagement/2024-05-01/certificate/method_workspacecertificaterefreshsecret.go new file mode 100644 index 00000000000..8354a402571 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/method_workspacecertificaterefreshsecret.go @@ -0,0 +1,55 @@ +package certificate + +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 WorkspaceCertificateRefreshSecretOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CertificateContract +} + +// WorkspaceCertificateRefreshSecret ... +func (c CertificateClient) WorkspaceCertificateRefreshSecret(ctx context.Context, id WorkspaceCertificateId) (result WorkspaceCertificateRefreshSecretOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/refreshSecret", 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 CertificateContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/model_certificatecontract.go b/resource-manager/apimanagement/2024-05-01/certificate/model_certificatecontract.go new file mode 100644 index 00000000000..15a790b5e4b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/model_certificatecontract.go @@ -0,0 +1,11 @@ +package certificate + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CertificateContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *CertificateContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/model_certificatecontractproperties.go b/resource-manager/apimanagement/2024-05-01/certificate/model_certificatecontractproperties.go new file mode 100644 index 00000000000..6ef4ff5eb2b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/model_certificatecontractproperties.go @@ -0,0 +1,26 @@ +package certificate + +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 CertificateContractProperties struct { + ExpirationDate string `json:"expirationDate"` + KeyVault *KeyVaultContractProperties `json:"keyVault,omitempty"` + Subject string `json:"subject"` + Thumbprint string `json:"thumbprint"` +} + +func (o *CertificateContractProperties) GetExpirationDateAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.ExpirationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *CertificateContractProperties) SetExpirationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpirationDate = formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/model_certificatecreateorupdateparameters.go b/resource-manager/apimanagement/2024-05-01/certificate/model_certificatecreateorupdateparameters.go new file mode 100644 index 00000000000..8e5582519ad --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/model_certificatecreateorupdateparameters.go @@ -0,0 +1,8 @@ +package certificate + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CertificateCreateOrUpdateParameters struct { + Properties *CertificateCreateOrUpdateProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/model_certificatecreateorupdateproperties.go b/resource-manager/apimanagement/2024-05-01/certificate/model_certificatecreateorupdateproperties.go new file mode 100644 index 00000000000..8253b21efb0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/model_certificatecreateorupdateproperties.go @@ -0,0 +1,10 @@ +package certificate + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CertificateCreateOrUpdateProperties struct { + Data *string `json:"data,omitempty"` + KeyVault *KeyVaultContractCreateProperties `json:"keyVault,omitempty"` + Password *string `json:"password,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/model_keyvaultcontractcreateproperties.go b/resource-manager/apimanagement/2024-05-01/certificate/model_keyvaultcontractcreateproperties.go new file mode 100644 index 00000000000..a279a78f88b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/model_keyvaultcontractcreateproperties.go @@ -0,0 +1,9 @@ +package certificate + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyVaultContractCreateProperties struct { + IdentityClientId *string `json:"identityClientId,omitempty"` + SecretIdentifier *string `json:"secretIdentifier,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/model_keyvaultcontractproperties.go b/resource-manager/apimanagement/2024-05-01/certificate/model_keyvaultcontractproperties.go new file mode 100644 index 00000000000..50a575bd344 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/model_keyvaultcontractproperties.go @@ -0,0 +1,10 @@ +package certificate + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyVaultContractProperties struct { + IdentityClientId *string `json:"identityClientId,omitempty"` + LastStatus *KeyVaultLastAccessStatusContractProperties `json:"lastStatus,omitempty"` + SecretIdentifier *string `json:"secretIdentifier,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/model_keyvaultlastaccessstatuscontractproperties.go b/resource-manager/apimanagement/2024-05-01/certificate/model_keyvaultlastaccessstatuscontractproperties.go new file mode 100644 index 00000000000..9596c23b8f6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/model_keyvaultlastaccessstatuscontractproperties.go @@ -0,0 +1,28 @@ +package certificate + +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 KeyVaultLastAccessStatusContractProperties struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` + TimeStampUtc *string `json:"timeStampUtc,omitempty"` +} + +func (o *KeyVaultLastAccessStatusContractProperties) GetTimeStampUtcAsTime() (*time.Time, error) { + if o.TimeStampUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.TimeStampUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *KeyVaultLastAccessStatusContractProperties) SetTimeStampUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.TimeStampUtc = &formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/certificate/predicates.go b/resource-manager/apimanagement/2024-05-01/certificate/predicates.go new file mode 100644 index 00000000000..62350ffb8a7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/predicates.go @@ -0,0 +1,27 @@ +package certificate + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CertificateContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p CertificateContractOperationPredicate) Matches(input CertificateContract) 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/apimanagement/2024-05-01/certificate/version.go b/resource-manager/apimanagement/2024-05-01/certificate/version.go new file mode 100644 index 00000000000..c5ac04b2418 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/certificate/version.go @@ -0,0 +1,12 @@ +package certificate + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/certificate/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/client.go b/resource-manager/apimanagement/2024-05-01/client.go new file mode 100644 index 00000000000..bbef8243518 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/client.go @@ -0,0 +1,1090 @@ +package v2024_05_01 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/allpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/api" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apidiagnostic" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apigateway" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apigatewayconfigconnection" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apiissue" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apiissueattachment" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apiissuecomment" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apimanagementgatewayskus" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apimanagementservice" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apimanagementserviceskus" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apimanagementworkspacelinks" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apioperation" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apioperationpolicy" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apioperationsbytag" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apioperationtag" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apipolicy" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apiproduct" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apirelease" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apirevision" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apisbytag" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apischema" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apitag" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apitagdescription" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apiversionset" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apiversionsets" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apiwiki" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/authorization" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/authorizationaccesspolicy" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/authorizationconfirmconsentcode" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/authorizationloginlinks" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/authorizationprovider" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/authorizations" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/authorizationserver" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/backend" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/backendreconnect" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/cache" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/certificate" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/contenttype" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/contenttypecontentitem" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/delegationsettings" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/deletedservice" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/diagnostic" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/documentationresource" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/emailtemplate" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/emailtemplates" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gateway" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewayapi" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewayinvalidatedebugcredentials" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewaylistkeys" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewaylisttrace" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/graphqlapiresolver" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/group" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/groupuser" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/identityprovider" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/issue" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/logger" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/namedvalue" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/networkstatus" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/notification" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/notificationrecipientemail" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/notificationrecipientuser" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/openidconnectprovider" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/performconnectivitycheck" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policy" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policydescription" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyrestriction" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyrestrictions" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/portalconfig" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/portalrevision" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/portalsettings" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/privateendpointconnections" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/product" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/productapi" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/productapilink" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/productgroup" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/productgrouplink" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/productpolicy" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/productsbytag" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/productsubscription" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/producttag" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/productwiki" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/quotabycounterkeys" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/region" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/reports" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/schema" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/signinsettings" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/signupsettings" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/skus" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/subscription" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tag" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tagapilink" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tagoperationlink" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tagproductlink" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tagresource" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tenantaccess" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tenantaccessgit" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tenantconfiguration" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tenantsettings" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/user" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/userconfirmationpasswordsend" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/usergroup" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/useridentity" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/users" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/usersubscription" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/usertoken" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/workspace" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/workspacepolicy" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + AllPolicies *allpolicies.AllPoliciesClient + Api *api.ApiClient + ApiDiagnostic *apidiagnostic.ApiDiagnosticClient + ApiGateway *apigateway.ApiGatewayClient + ApiGatewayConfigConnection *apigatewayconfigconnection.ApiGatewayConfigConnectionClient + ApiIssue *apiissue.ApiIssueClient + ApiIssueAttachment *apiissueattachment.ApiIssueAttachmentClient + ApiIssueComment *apiissuecomment.ApiIssueCommentClient + ApiManagementGatewaySkus *apimanagementgatewayskus.ApiManagementGatewaySkusClient + ApiManagementService *apimanagementservice.ApiManagementServiceClient + ApiManagementServiceSkus *apimanagementserviceskus.ApiManagementServiceSkusClient + ApiManagementWorkspaceLinks *apimanagementworkspacelinks.ApiManagementWorkspaceLinksClient + ApiOperation *apioperation.ApiOperationClient + ApiOperationPolicy *apioperationpolicy.ApiOperationPolicyClient + ApiOperationTag *apioperationtag.ApiOperationTagClient + ApiOperationsByTag *apioperationsbytag.ApiOperationsByTagClient + ApiPolicy *apipolicy.ApiPolicyClient + ApiProduct *apiproduct.ApiProductClient + ApiRelease *apirelease.ApiReleaseClient + ApiRevision *apirevision.ApiRevisionClient + ApiSchema *apischema.ApiSchemaClient + ApiTag *apitag.ApiTagClient + ApiTagDescription *apitagdescription.ApiTagDescriptionClient + ApiVersionSet *apiversionset.ApiVersionSetClient + ApiVersionSets *apiversionsets.ApiVersionSetsClient + ApiWiki *apiwiki.ApiWikiClient + ApisByTag *apisbytag.ApisByTagClient + Authorization *authorization.AuthorizationClient + AuthorizationAccessPolicy *authorizationaccesspolicy.AuthorizationAccessPolicyClient + AuthorizationConfirmConsentCode *authorizationconfirmconsentcode.AuthorizationConfirmConsentCodeClient + AuthorizationLoginLinks *authorizationloginlinks.AuthorizationLoginLinksClient + AuthorizationProvider *authorizationprovider.AuthorizationProviderClient + AuthorizationServer *authorizationserver.AuthorizationServerClient + Authorizations *authorizations.AuthorizationsClient + Backend *backend.BackendClient + BackendReconnect *backendreconnect.BackendReconnectClient + Cache *cache.CacheClient + Certificate *certificate.CertificateClient + ContentType *contenttype.ContentTypeClient + ContentTypeContentItem *contenttypecontentitem.ContentTypeContentItemClient + DelegationSettings *delegationsettings.DelegationSettingsClient + DeletedService *deletedservice.DeletedServiceClient + Diagnostic *diagnostic.DiagnosticClient + DocumentationResource *documentationresource.DocumentationResourceClient + EmailTemplate *emailtemplate.EmailTemplateClient + EmailTemplates *emailtemplates.EmailTemplatesClient + Gateway *gateway.GatewayClient + GatewayApi *gatewayapi.GatewayApiClient + GatewayCertificateAuthority *gatewaycertificateauthority.GatewayCertificateAuthorityClient + GatewayGenerateToken *gatewaygeneratetoken.GatewayGenerateTokenClient + GatewayHostnameConfiguration *gatewayhostnameconfiguration.GatewayHostnameConfigurationClient + GatewayInvalidateDebugCredentials *gatewayinvalidatedebugcredentials.GatewayInvalidateDebugCredentialsClient + GatewayListDebugCredentials *gatewaylistdebugcredentials.GatewayListDebugCredentialsClient + GatewayListKeys *gatewaylistkeys.GatewayListKeysClient + GatewayListTrace *gatewaylisttrace.GatewayListTraceClient + GatewayRegenerateKey *gatewayregeneratekey.GatewayRegenerateKeyClient + GraphQLApiResolver *graphqlapiresolver.GraphQLApiResolverClient + GraphQLApiResolverPolicy *graphqlapiresolverpolicy.GraphQLApiResolverPolicyClient + Group *group.GroupClient + GroupUser *groupuser.GroupUserClient + IdentityProvider *identityprovider.IdentityProviderClient + Issue *issue.IssueClient + Logger *logger.LoggerClient + NamedValue *namedvalue.NamedValueClient + NetworkStatus *networkstatus.NetworkStatusClient + Notification *notification.NotificationClient + NotificationRecipientEmail *notificationrecipientemail.NotificationRecipientEmailClient + NotificationRecipientUser *notificationrecipientuser.NotificationRecipientUserClient + OpenidConnectProvider *openidconnectprovider.OpenidConnectProviderClient + OutboundNetworkDependenciesEndpoints *outboundnetworkdependenciesendpoints.OutboundNetworkDependenciesEndpointsClient + PerformConnectivityCheck *performconnectivitycheck.PerformConnectivityCheckClient + Policy *policy.PolicyClient + PolicyDescription *policydescription.PolicyDescriptionClient + PolicyFragment *policyfragment.PolicyFragmentClient + PolicyRestriction *policyrestriction.PolicyRestrictionClient + PolicyRestrictions *policyrestrictions.PolicyRestrictionsClient + PolicyRestrictionsValidations *policyrestrictionsvalidations.PolicyRestrictionsValidationsClient + PortalConfig *portalconfig.PortalConfigClient + PortalRevision *portalrevision.PortalRevisionClient + PortalSettings *portalsettings.PortalSettingsClient + PrivateEndpointConnections *privateendpointconnections.PrivateEndpointConnectionsClient + Product *product.ProductClient + ProductApi *productapi.ProductApiClient + ProductApiLink *productapilink.ProductApiLinkClient + ProductGroup *productgroup.ProductGroupClient + ProductGroupLink *productgrouplink.ProductGroupLinkClient + ProductPolicy *productpolicy.ProductPolicyClient + ProductSubscription *productsubscription.ProductSubscriptionClient + ProductTag *producttag.ProductTagClient + ProductWiki *productwiki.ProductWikiClient + ProductsByTag *productsbytag.ProductsByTagClient + QuotaByCounterKeys *quotabycounterkeys.QuotaByCounterKeysClient + QuotaByPeriodKeys *quotabyperiodkeys.QuotaByPeriodKeysClient + Region *region.RegionClient + Reports *reports.ReportsClient + Schema *schema.SchemaClient + SignInSettings *signinsettings.SignInSettingsClient + SignUpSettings *signupsettings.SignUpSettingsClient + Skus *skus.SkusClient + Subscription *subscription.SubscriptionClient + Tag *tag.TagClient + TagApiLink *tagapilink.TagApiLinkClient + TagOperationLink *tagoperationlink.TagOperationLinkClient + TagProductLink *tagproductlink.TagProductLinkClient + TagResource *tagresource.TagResourceClient + TenantAccess *tenantaccess.TenantAccessClient + TenantAccessGit *tenantaccessgit.TenantAccessGitClient + TenantConfiguration *tenantconfiguration.TenantConfigurationClient + TenantConfigurationSyncState *tenantconfigurationsyncstate.TenantConfigurationSyncStateClient + TenantSettings *tenantsettings.TenantSettingsClient + User *user.UserClient + UserConfirmationPasswordSend *userconfirmationpasswordsend.UserConfirmationPasswordSendClient + UserGroup *usergroup.UserGroupClient + UserIdentity *useridentity.UserIdentityClient + UserSubscription *usersubscription.UserSubscriptionClient + UserToken *usertoken.UserTokenClient + Users *users.UsersClient + Workspace *workspace.WorkspaceClient + WorkspacePolicy *workspacepolicy.WorkspacePolicyClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + allPoliciesClient, err := allpolicies.NewAllPoliciesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AllPolicies client: %+v", err) + } + configureFunc(allPoliciesClient.Client) + + apiClient, err := api.NewApiClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Api client: %+v", err) + } + configureFunc(apiClient.Client) + + apiDiagnosticClient, err := apidiagnostic.NewApiDiagnosticClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiDiagnostic client: %+v", err) + } + configureFunc(apiDiagnosticClient.Client) + + apiGatewayClient, err := apigateway.NewApiGatewayClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiGateway client: %+v", err) + } + configureFunc(apiGatewayClient.Client) + + apiGatewayConfigConnectionClient, err := apigatewayconfigconnection.NewApiGatewayConfigConnectionClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiGatewayConfigConnection client: %+v", err) + } + configureFunc(apiGatewayConfigConnectionClient.Client) + + apiIssueAttachmentClient, err := apiissueattachment.NewApiIssueAttachmentClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiIssueAttachment client: %+v", err) + } + configureFunc(apiIssueAttachmentClient.Client) + + apiIssueClient, err := apiissue.NewApiIssueClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiIssue client: %+v", err) + } + configureFunc(apiIssueClient.Client) + + apiIssueCommentClient, err := apiissuecomment.NewApiIssueCommentClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiIssueComment client: %+v", err) + } + configureFunc(apiIssueCommentClient.Client) + + apiManagementGatewaySkusClient, err := apimanagementgatewayskus.NewApiManagementGatewaySkusClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiManagementGatewaySkus client: %+v", err) + } + configureFunc(apiManagementGatewaySkusClient.Client) + + apiManagementServiceClient, err := apimanagementservice.NewApiManagementServiceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiManagementService client: %+v", err) + } + configureFunc(apiManagementServiceClient.Client) + + apiManagementServiceSkusClient, err := apimanagementserviceskus.NewApiManagementServiceSkusClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiManagementServiceSkus client: %+v", err) + } + configureFunc(apiManagementServiceSkusClient.Client) + + apiManagementWorkspaceLinksClient, err := apimanagementworkspacelinks.NewApiManagementWorkspaceLinksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiManagementWorkspaceLinks client: %+v", err) + } + configureFunc(apiManagementWorkspaceLinksClient.Client) + + apiOperationClient, err := apioperation.NewApiOperationClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiOperation client: %+v", err) + } + configureFunc(apiOperationClient.Client) + + apiOperationPolicyClient, err := apioperationpolicy.NewApiOperationPolicyClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiOperationPolicy client: %+v", err) + } + configureFunc(apiOperationPolicyClient.Client) + + apiOperationTagClient, err := apioperationtag.NewApiOperationTagClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiOperationTag client: %+v", err) + } + configureFunc(apiOperationTagClient.Client) + + apiOperationsByTagClient, err := apioperationsbytag.NewApiOperationsByTagClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiOperationsByTag client: %+v", err) + } + configureFunc(apiOperationsByTagClient.Client) + + apiPolicyClient, err := apipolicy.NewApiPolicyClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiPolicy client: %+v", err) + } + configureFunc(apiPolicyClient.Client) + + apiProductClient, err := apiproduct.NewApiProductClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiProduct client: %+v", err) + } + configureFunc(apiProductClient.Client) + + apiReleaseClient, err := apirelease.NewApiReleaseClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiRelease client: %+v", err) + } + configureFunc(apiReleaseClient.Client) + + apiRevisionClient, err := apirevision.NewApiRevisionClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiRevision client: %+v", err) + } + configureFunc(apiRevisionClient.Client) + + apiSchemaClient, err := apischema.NewApiSchemaClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiSchema client: %+v", err) + } + configureFunc(apiSchemaClient.Client) + + apiTagClient, err := apitag.NewApiTagClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiTag client: %+v", err) + } + configureFunc(apiTagClient.Client) + + apiTagDescriptionClient, err := apitagdescription.NewApiTagDescriptionClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiTagDescription client: %+v", err) + } + configureFunc(apiTagDescriptionClient.Client) + + apiVersionSetClient, err := apiversionset.NewApiVersionSetClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiVersionSet client: %+v", err) + } + configureFunc(apiVersionSetClient.Client) + + apiVersionSetsClient, err := apiversionsets.NewApiVersionSetsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiVersionSets client: %+v", err) + } + configureFunc(apiVersionSetsClient.Client) + + apiWikiClient, err := apiwiki.NewApiWikiClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiWiki client: %+v", err) + } + configureFunc(apiWikiClient.Client) + + apisByTagClient, err := apisbytag.NewApisByTagClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApisByTag client: %+v", err) + } + configureFunc(apisByTagClient.Client) + + authorizationAccessPolicyClient, err := authorizationaccesspolicy.NewAuthorizationAccessPolicyClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AuthorizationAccessPolicy client: %+v", err) + } + configureFunc(authorizationAccessPolicyClient.Client) + + authorizationClient, err := authorization.NewAuthorizationClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Authorization client: %+v", err) + } + configureFunc(authorizationClient.Client) + + authorizationConfirmConsentCodeClient, err := authorizationconfirmconsentcode.NewAuthorizationConfirmConsentCodeClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AuthorizationConfirmConsentCode client: %+v", err) + } + configureFunc(authorizationConfirmConsentCodeClient.Client) + + authorizationLoginLinksClient, err := authorizationloginlinks.NewAuthorizationLoginLinksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AuthorizationLoginLinks client: %+v", err) + } + configureFunc(authorizationLoginLinksClient.Client) + + authorizationProviderClient, err := authorizationprovider.NewAuthorizationProviderClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AuthorizationProvider client: %+v", err) + } + configureFunc(authorizationProviderClient.Client) + + authorizationServerClient, err := authorizationserver.NewAuthorizationServerClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AuthorizationServer client: %+v", err) + } + configureFunc(authorizationServerClient.Client) + + authorizationsClient, err := authorizations.NewAuthorizationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Authorizations client: %+v", err) + } + configureFunc(authorizationsClient.Client) + + backendClient, err := backend.NewBackendClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Backend client: %+v", err) + } + configureFunc(backendClient.Client) + + backendReconnectClient, err := backendreconnect.NewBackendReconnectClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building BackendReconnect client: %+v", err) + } + configureFunc(backendReconnectClient.Client) + + cacheClient, err := cache.NewCacheClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Cache client: %+v", err) + } + configureFunc(cacheClient.Client) + + certificateClient, err := certificate.NewCertificateClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Certificate client: %+v", err) + } + configureFunc(certificateClient.Client) + + contentTypeClient, err := contenttype.NewContentTypeClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ContentType client: %+v", err) + } + configureFunc(contentTypeClient.Client) + + contentTypeContentItemClient, err := contenttypecontentitem.NewContentTypeContentItemClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ContentTypeContentItem client: %+v", err) + } + configureFunc(contentTypeContentItemClient.Client) + + delegationSettingsClient, err := delegationsettings.NewDelegationSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DelegationSettings client: %+v", err) + } + configureFunc(delegationSettingsClient.Client) + + deletedServiceClient, err := deletedservice.NewDeletedServiceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DeletedService client: %+v", err) + } + configureFunc(deletedServiceClient.Client) + + diagnosticClient, err := diagnostic.NewDiagnosticClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Diagnostic client: %+v", err) + } + configureFunc(diagnosticClient.Client) + + documentationResourceClient, err := documentationresource.NewDocumentationResourceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DocumentationResource client: %+v", err) + } + configureFunc(documentationResourceClient.Client) + + emailTemplateClient, err := emailtemplate.NewEmailTemplateClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building EmailTemplate client: %+v", err) + } + configureFunc(emailTemplateClient.Client) + + emailTemplatesClient, err := emailtemplates.NewEmailTemplatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building EmailTemplates client: %+v", err) + } + configureFunc(emailTemplatesClient.Client) + + gatewayApiClient, err := gatewayapi.NewGatewayApiClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building GatewayApi client: %+v", err) + } + configureFunc(gatewayApiClient.Client) + + gatewayCertificateAuthorityClient, err := gatewaycertificateauthority.NewGatewayCertificateAuthorityClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building GatewayCertificateAuthority client: %+v", err) + } + configureFunc(gatewayCertificateAuthorityClient.Client) + + gatewayClient, err := gateway.NewGatewayClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Gateway client: %+v", err) + } + configureFunc(gatewayClient.Client) + + gatewayGenerateTokenClient, err := gatewaygeneratetoken.NewGatewayGenerateTokenClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building GatewayGenerateToken client: %+v", err) + } + configureFunc(gatewayGenerateTokenClient.Client) + + gatewayHostnameConfigurationClient, err := gatewayhostnameconfiguration.NewGatewayHostnameConfigurationClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building GatewayHostnameConfiguration client: %+v", err) + } + configureFunc(gatewayHostnameConfigurationClient.Client) + + gatewayInvalidateDebugCredentialsClient, err := gatewayinvalidatedebugcredentials.NewGatewayInvalidateDebugCredentialsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building GatewayInvalidateDebugCredentials client: %+v", err) + } + configureFunc(gatewayInvalidateDebugCredentialsClient.Client) + + gatewayListDebugCredentialsClient, err := gatewaylistdebugcredentials.NewGatewayListDebugCredentialsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building GatewayListDebugCredentials client: %+v", err) + } + configureFunc(gatewayListDebugCredentialsClient.Client) + + gatewayListKeysClient, err := gatewaylistkeys.NewGatewayListKeysClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building GatewayListKeys client: %+v", err) + } + configureFunc(gatewayListKeysClient.Client) + + gatewayListTraceClient, err := gatewaylisttrace.NewGatewayListTraceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building GatewayListTrace client: %+v", err) + } + configureFunc(gatewayListTraceClient.Client) + + gatewayRegenerateKeyClient, err := gatewayregeneratekey.NewGatewayRegenerateKeyClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building GatewayRegenerateKey client: %+v", err) + } + configureFunc(gatewayRegenerateKeyClient.Client) + + graphQLApiResolverClient, err := graphqlapiresolver.NewGraphQLApiResolverClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building GraphQLApiResolver client: %+v", err) + } + configureFunc(graphQLApiResolverClient.Client) + + graphQLApiResolverPolicyClient, err := graphqlapiresolverpolicy.NewGraphQLApiResolverPolicyClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building GraphQLApiResolverPolicy client: %+v", err) + } + configureFunc(graphQLApiResolverPolicyClient.Client) + + groupClient, err := group.NewGroupClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Group client: %+v", err) + } + configureFunc(groupClient.Client) + + groupUserClient, err := groupuser.NewGroupUserClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building GroupUser client: %+v", err) + } + configureFunc(groupUserClient.Client) + + identityProviderClient, err := identityprovider.NewIdentityProviderClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IdentityProvider client: %+v", err) + } + configureFunc(identityProviderClient.Client) + + issueClient, err := issue.NewIssueClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Issue client: %+v", err) + } + configureFunc(issueClient.Client) + + loggerClient, err := logger.NewLoggerClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Logger client: %+v", err) + } + configureFunc(loggerClient.Client) + + namedValueClient, err := namedvalue.NewNamedValueClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building NamedValue client: %+v", err) + } + configureFunc(namedValueClient.Client) + + networkStatusClient, err := networkstatus.NewNetworkStatusClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building NetworkStatus client: %+v", err) + } + configureFunc(networkStatusClient.Client) + + notificationClient, err := notification.NewNotificationClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Notification client: %+v", err) + } + configureFunc(notificationClient.Client) + + notificationRecipientEmailClient, err := notificationrecipientemail.NewNotificationRecipientEmailClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building NotificationRecipientEmail client: %+v", err) + } + configureFunc(notificationRecipientEmailClient.Client) + + notificationRecipientUserClient, err := notificationrecipientuser.NewNotificationRecipientUserClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building NotificationRecipientUser client: %+v", err) + } + configureFunc(notificationRecipientUserClient.Client) + + openidConnectProviderClient, err := openidconnectprovider.NewOpenidConnectProviderClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building OpenidConnectProvider client: %+v", err) + } + configureFunc(openidConnectProviderClient.Client) + + outboundNetworkDependenciesEndpointsClient, err := outboundnetworkdependenciesendpoints.NewOutboundNetworkDependenciesEndpointsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building OutboundNetworkDependenciesEndpoints client: %+v", err) + } + configureFunc(outboundNetworkDependenciesEndpointsClient.Client) + + performConnectivityCheckClient, err := performconnectivitycheck.NewPerformConnectivityCheckClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PerformConnectivityCheck client: %+v", err) + } + configureFunc(performConnectivityCheckClient.Client) + + policyClient, err := policy.NewPolicyClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Policy client: %+v", err) + } + configureFunc(policyClient.Client) + + policyDescriptionClient, err := policydescription.NewPolicyDescriptionClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PolicyDescription client: %+v", err) + } + configureFunc(policyDescriptionClient.Client) + + policyFragmentClient, err := policyfragment.NewPolicyFragmentClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PolicyFragment client: %+v", err) + } + configureFunc(policyFragmentClient.Client) + + policyRestrictionClient, err := policyrestriction.NewPolicyRestrictionClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PolicyRestriction client: %+v", err) + } + configureFunc(policyRestrictionClient.Client) + + policyRestrictionsClient, err := policyrestrictions.NewPolicyRestrictionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PolicyRestrictions client: %+v", err) + } + configureFunc(policyRestrictionsClient.Client) + + policyRestrictionsValidationsClient, err := policyrestrictionsvalidations.NewPolicyRestrictionsValidationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PolicyRestrictionsValidations client: %+v", err) + } + configureFunc(policyRestrictionsValidationsClient.Client) + + portalConfigClient, err := portalconfig.NewPortalConfigClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PortalConfig client: %+v", err) + } + configureFunc(portalConfigClient.Client) + + portalRevisionClient, err := portalrevision.NewPortalRevisionClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PortalRevision client: %+v", err) + } + configureFunc(portalRevisionClient.Client) + + portalSettingsClient, err := portalsettings.NewPortalSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PortalSettings client: %+v", err) + } + configureFunc(portalSettingsClient.Client) + + privateEndpointConnectionsClient, err := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateEndpointConnections client: %+v", err) + } + configureFunc(privateEndpointConnectionsClient.Client) + + productApiClient, err := productapi.NewProductApiClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ProductApi client: %+v", err) + } + configureFunc(productApiClient.Client) + + productApiLinkClient, err := productapilink.NewProductApiLinkClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ProductApiLink client: %+v", err) + } + configureFunc(productApiLinkClient.Client) + + productClient, err := product.NewProductClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Product client: %+v", err) + } + configureFunc(productClient.Client) + + productGroupClient, err := productgroup.NewProductGroupClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ProductGroup client: %+v", err) + } + configureFunc(productGroupClient.Client) + + productGroupLinkClient, err := productgrouplink.NewProductGroupLinkClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ProductGroupLink client: %+v", err) + } + configureFunc(productGroupLinkClient.Client) + + productPolicyClient, err := productpolicy.NewProductPolicyClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ProductPolicy client: %+v", err) + } + configureFunc(productPolicyClient.Client) + + productSubscriptionClient, err := productsubscription.NewProductSubscriptionClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ProductSubscription client: %+v", err) + } + configureFunc(productSubscriptionClient.Client) + + productTagClient, err := producttag.NewProductTagClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ProductTag client: %+v", err) + } + configureFunc(productTagClient.Client) + + productWikiClient, err := productwiki.NewProductWikiClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ProductWiki client: %+v", err) + } + configureFunc(productWikiClient.Client) + + productsByTagClient, err := productsbytag.NewProductsByTagClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ProductsByTag client: %+v", err) + } + configureFunc(productsByTagClient.Client) + + quotaByCounterKeysClient, err := quotabycounterkeys.NewQuotaByCounterKeysClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building QuotaByCounterKeys client: %+v", err) + } + configureFunc(quotaByCounterKeysClient.Client) + + quotaByPeriodKeysClient, err := quotabyperiodkeys.NewQuotaByPeriodKeysClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building QuotaByPeriodKeys client: %+v", err) + } + configureFunc(quotaByPeriodKeysClient.Client) + + regionClient, err := region.NewRegionClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Region client: %+v", err) + } + configureFunc(regionClient.Client) + + reportsClient, err := reports.NewReportsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Reports client: %+v", err) + } + configureFunc(reportsClient.Client) + + schemaClient, err := schema.NewSchemaClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Schema client: %+v", err) + } + configureFunc(schemaClient.Client) + + signInSettingsClient, err := signinsettings.NewSignInSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SignInSettings client: %+v", err) + } + configureFunc(signInSettingsClient.Client) + + signUpSettingsClient, err := signupsettings.NewSignUpSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SignUpSettings client: %+v", err) + } + configureFunc(signUpSettingsClient.Client) + + skusClient, err := skus.NewSkusClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Skus client: %+v", err) + } + configureFunc(skusClient.Client) + + subscriptionClient, err := subscription.NewSubscriptionClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Subscription client: %+v", err) + } + configureFunc(subscriptionClient.Client) + + tagApiLinkClient, err := tagapilink.NewTagApiLinkClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building TagApiLink client: %+v", err) + } + configureFunc(tagApiLinkClient.Client) + + tagClient, err := tag.NewTagClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Tag client: %+v", err) + } + configureFunc(tagClient.Client) + + tagOperationLinkClient, err := tagoperationlink.NewTagOperationLinkClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building TagOperationLink client: %+v", err) + } + configureFunc(tagOperationLinkClient.Client) + + tagProductLinkClient, err := tagproductlink.NewTagProductLinkClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building TagProductLink client: %+v", err) + } + configureFunc(tagProductLinkClient.Client) + + tagResourceClient, err := tagresource.NewTagResourceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building TagResource client: %+v", err) + } + configureFunc(tagResourceClient.Client) + + tenantAccessClient, err := tenantaccess.NewTenantAccessClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building TenantAccess client: %+v", err) + } + configureFunc(tenantAccessClient.Client) + + tenantAccessGitClient, err := tenantaccessgit.NewTenantAccessGitClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building TenantAccessGit client: %+v", err) + } + configureFunc(tenantAccessGitClient.Client) + + tenantConfigurationClient, err := tenantconfiguration.NewTenantConfigurationClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building TenantConfiguration client: %+v", err) + } + configureFunc(tenantConfigurationClient.Client) + + tenantConfigurationSyncStateClient, err := tenantconfigurationsyncstate.NewTenantConfigurationSyncStateClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building TenantConfigurationSyncState client: %+v", err) + } + configureFunc(tenantConfigurationSyncStateClient.Client) + + tenantSettingsClient, err := tenantsettings.NewTenantSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building TenantSettings client: %+v", err) + } + configureFunc(tenantSettingsClient.Client) + + userClient, err := user.NewUserClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building User client: %+v", err) + } + configureFunc(userClient.Client) + + userConfirmationPasswordSendClient, err := userconfirmationpasswordsend.NewUserConfirmationPasswordSendClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building UserConfirmationPasswordSend client: %+v", err) + } + configureFunc(userConfirmationPasswordSendClient.Client) + + userGroupClient, err := usergroup.NewUserGroupClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building UserGroup client: %+v", err) + } + configureFunc(userGroupClient.Client) + + userIdentityClient, err := useridentity.NewUserIdentityClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building UserIdentity client: %+v", err) + } + configureFunc(userIdentityClient.Client) + + userSubscriptionClient, err := usersubscription.NewUserSubscriptionClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building UserSubscription client: %+v", err) + } + configureFunc(userSubscriptionClient.Client) + + userTokenClient, err := usertoken.NewUserTokenClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building UserToken client: %+v", err) + } + configureFunc(userTokenClient.Client) + + usersClient, err := users.NewUsersClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Users client: %+v", err) + } + configureFunc(usersClient.Client) + + workspaceClient, err := workspace.NewWorkspaceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Workspace client: %+v", err) + } + configureFunc(workspaceClient.Client) + + workspacePolicyClient, err := workspacepolicy.NewWorkspacePolicyClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building WorkspacePolicy client: %+v", err) + } + configureFunc(workspacePolicyClient.Client) + + return &Client{ + AllPolicies: allPoliciesClient, + Api: apiClient, + ApiDiagnostic: apiDiagnosticClient, + ApiGateway: apiGatewayClient, + ApiGatewayConfigConnection: apiGatewayConfigConnectionClient, + ApiIssue: apiIssueClient, + ApiIssueAttachment: apiIssueAttachmentClient, + ApiIssueComment: apiIssueCommentClient, + ApiManagementGatewaySkus: apiManagementGatewaySkusClient, + ApiManagementService: apiManagementServiceClient, + ApiManagementServiceSkus: apiManagementServiceSkusClient, + ApiManagementWorkspaceLinks: apiManagementWorkspaceLinksClient, + ApiOperation: apiOperationClient, + ApiOperationPolicy: apiOperationPolicyClient, + ApiOperationTag: apiOperationTagClient, + ApiOperationsByTag: apiOperationsByTagClient, + ApiPolicy: apiPolicyClient, + ApiProduct: apiProductClient, + ApiRelease: apiReleaseClient, + ApiRevision: apiRevisionClient, + ApiSchema: apiSchemaClient, + ApiTag: apiTagClient, + ApiTagDescription: apiTagDescriptionClient, + ApiVersionSet: apiVersionSetClient, + ApiVersionSets: apiVersionSetsClient, + ApiWiki: apiWikiClient, + ApisByTag: apisByTagClient, + Authorization: authorizationClient, + AuthorizationAccessPolicy: authorizationAccessPolicyClient, + AuthorizationConfirmConsentCode: authorizationConfirmConsentCodeClient, + AuthorizationLoginLinks: authorizationLoginLinksClient, + AuthorizationProvider: authorizationProviderClient, + AuthorizationServer: authorizationServerClient, + Authorizations: authorizationsClient, + Backend: backendClient, + BackendReconnect: backendReconnectClient, + Cache: cacheClient, + Certificate: certificateClient, + ContentType: contentTypeClient, + ContentTypeContentItem: contentTypeContentItemClient, + DelegationSettings: delegationSettingsClient, + DeletedService: deletedServiceClient, + Diagnostic: diagnosticClient, + DocumentationResource: documentationResourceClient, + EmailTemplate: emailTemplateClient, + EmailTemplates: emailTemplatesClient, + Gateway: gatewayClient, + GatewayApi: gatewayApiClient, + GatewayCertificateAuthority: gatewayCertificateAuthorityClient, + GatewayGenerateToken: gatewayGenerateTokenClient, + GatewayHostnameConfiguration: gatewayHostnameConfigurationClient, + GatewayInvalidateDebugCredentials: gatewayInvalidateDebugCredentialsClient, + GatewayListDebugCredentials: gatewayListDebugCredentialsClient, + GatewayListKeys: gatewayListKeysClient, + GatewayListTrace: gatewayListTraceClient, + GatewayRegenerateKey: gatewayRegenerateKeyClient, + GraphQLApiResolver: graphQLApiResolverClient, + GraphQLApiResolverPolicy: graphQLApiResolverPolicyClient, + Group: groupClient, + GroupUser: groupUserClient, + IdentityProvider: identityProviderClient, + Issue: issueClient, + Logger: loggerClient, + NamedValue: namedValueClient, + NetworkStatus: networkStatusClient, + Notification: notificationClient, + NotificationRecipientEmail: notificationRecipientEmailClient, + NotificationRecipientUser: notificationRecipientUserClient, + OpenidConnectProvider: openidConnectProviderClient, + OutboundNetworkDependenciesEndpoints: outboundNetworkDependenciesEndpointsClient, + PerformConnectivityCheck: performConnectivityCheckClient, + Policy: policyClient, + PolicyDescription: policyDescriptionClient, + PolicyFragment: policyFragmentClient, + PolicyRestriction: policyRestrictionClient, + PolicyRestrictions: policyRestrictionsClient, + PolicyRestrictionsValidations: policyRestrictionsValidationsClient, + PortalConfig: portalConfigClient, + PortalRevision: portalRevisionClient, + PortalSettings: portalSettingsClient, + PrivateEndpointConnections: privateEndpointConnectionsClient, + Product: productClient, + ProductApi: productApiClient, + ProductApiLink: productApiLinkClient, + ProductGroup: productGroupClient, + ProductGroupLink: productGroupLinkClient, + ProductPolicy: productPolicyClient, + ProductSubscription: productSubscriptionClient, + ProductTag: productTagClient, + ProductWiki: productWikiClient, + ProductsByTag: productsByTagClient, + QuotaByCounterKeys: quotaByCounterKeysClient, + QuotaByPeriodKeys: quotaByPeriodKeysClient, + Region: regionClient, + Reports: reportsClient, + Schema: schemaClient, + SignInSettings: signInSettingsClient, + SignUpSettings: signUpSettingsClient, + Skus: skusClient, + Subscription: subscriptionClient, + Tag: tagClient, + TagApiLink: tagApiLinkClient, + TagOperationLink: tagOperationLinkClient, + TagProductLink: tagProductLinkClient, + TagResource: tagResourceClient, + TenantAccess: tenantAccessClient, + TenantAccessGit: tenantAccessGitClient, + TenantConfiguration: tenantConfigurationClient, + TenantConfigurationSyncState: tenantConfigurationSyncStateClient, + TenantSettings: tenantSettingsClient, + User: userClient, + UserConfirmationPasswordSend: userConfirmationPasswordSendClient, + UserGroup: userGroupClient, + UserIdentity: userIdentityClient, + UserSubscription: userSubscriptionClient, + UserToken: userTokenClient, + Users: usersClient, + Workspace: workspaceClient, + WorkspacePolicy: workspacePolicyClient, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttype/README.md b/resource-manager/apimanagement/2024-05-01/contenttype/README.md new file mode 100644 index 00000000000..57ff8d51e2c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttype/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/contenttype` Documentation + +The `contenttype` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/contenttype" +``` + + +### Client Initialization + +```go +client := contenttype.NewContentTypeClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ContentTypeClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := contenttype.NewContentTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "contentTypeIdValue") + +payload := contenttype.ContentTypeContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, contenttype.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContentTypeClient.Delete` + +```go +ctx := context.TODO() +id := contenttype.NewContentTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "contentTypeIdValue") + +read, err := client.Delete(ctx, id, contenttype.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContentTypeClient.Get` + +```go +ctx := context.TODO() +id := contenttype.NewContentTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "contentTypeIdValue") + +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: `ContentTypeClient.ListByService` + +```go +ctx := context.TODO() +id := contenttype.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id)` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/contenttype/client.go b/resource-manager/apimanagement/2024-05-01/contenttype/client.go new file mode 100644 index 00000000000..86436fb159e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttype/client.go @@ -0,0 +1,26 @@ +package contenttype + +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 ContentTypeClient struct { + Client *resourcemanager.Client +} + +func NewContentTypeClientWithBaseURI(sdkApi sdkEnv.Api) (*ContentTypeClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "contenttype", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ContentTypeClient: %+v", err) + } + + return &ContentTypeClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttype/id_contenttype.go b/resource-manager/apimanagement/2024-05-01/contenttype/id_contenttype.go new file mode 100644 index 00000000000..35dbd65c28b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttype/id_contenttype.go @@ -0,0 +1,139 @@ +package contenttype + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ContentTypeId{}) +} + +var _ resourceids.ResourceId = &ContentTypeId{} + +// ContentTypeId is a struct representing the Resource ID for a Content Type +type ContentTypeId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ContentTypeId string +} + +// NewContentTypeID returns a new ContentTypeId struct +func NewContentTypeID(subscriptionId string, resourceGroupName string, serviceName string, contentTypeId string) ContentTypeId { + return ContentTypeId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ContentTypeId: contentTypeId, + } +} + +// ParseContentTypeID parses 'input' into a ContentTypeId +func ParseContentTypeID(input string) (*ContentTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContentTypeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContentTypeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseContentTypeIDInsensitively parses 'input' case-insensitively into a ContentTypeId +// note: this method should only be used for API response data and not user input +func ParseContentTypeIDInsensitively(input string) (*ContentTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContentTypeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContentTypeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ContentTypeId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ContentTypeId, ok = input.Parsed["contentTypeId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "contentTypeId", input) + } + + return nil +} + +// ValidateContentTypeID checks that 'input' can be parsed as a Content Type ID +func ValidateContentTypeID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseContentTypeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Content Type ID +func (id ContentTypeId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/contentTypes/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ContentTypeId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Content Type ID +func (id ContentTypeId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticContentTypes", "contentTypes", "contentTypes"), + resourceids.UserSpecifiedSegment("contentTypeId", "contentTypeIdValue"), + } +} + +// String returns a human-readable description of this Content Type ID +func (id ContentTypeId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Content Type: %q", id.ContentTypeId), + } + return fmt.Sprintf("Content Type (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttype/id_contenttype_test.go b/resource-manager/apimanagement/2024-05-01/contenttype/id_contenttype_test.go new file mode 100644 index 00000000000..dd383306266 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttype/id_contenttype_test.go @@ -0,0 +1,327 @@ +package contenttype + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ContentTypeId{} + +func TestNewContentTypeID(t *testing.T) { + id := NewContentTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "contentTypeIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ContentTypeId != "contentTypeIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ContentTypeId'", id.ContentTypeId, "contentTypeIdValue") + } +} + +func TestFormatContentTypeID(t *testing.T) { + actual := NewContentTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "contentTypeIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes/contentTypeIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseContentTypeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContentTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes/contentTypeIdValue", + Expected: &ContentTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ContentTypeId: "contentTypeIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes/contentTypeIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContentTypeID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ContentTypeId != v.Expected.ContentTypeId { + t.Fatalf("Expected %q but got %q for ContentTypeId", v.Expected.ContentTypeId, actual.ContentTypeId) + } + + } +} + +func TestParseContentTypeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContentTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/cOnTeNtTyPeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes/contentTypeIdValue", + Expected: &ContentTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ContentTypeId: "contentTypeIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes/contentTypeIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/cOnTeNtTyPeS/cOnTeNtTyPeIdVaLuE", + Expected: &ContentTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ContentTypeId: "cOnTeNtTyPeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/cOnTeNtTyPeS/cOnTeNtTyPeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContentTypeIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ContentTypeId != v.Expected.ContentTypeId { + t.Fatalf("Expected %q but got %q for ContentTypeId", v.Expected.ContentTypeId, actual.ContentTypeId) + } + + } +} + +func TestSegmentsForContentTypeId(t *testing.T) { + segments := ContentTypeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ContentTypeId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttype/id_service.go b/resource-manager/apimanagement/2024-05-01/contenttype/id_service.go new file mode 100644 index 00000000000..1241f699f16 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttype/id_service.go @@ -0,0 +1,130 @@ +package contenttype + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttype/id_service_test.go b/resource-manager/apimanagement/2024-05-01/contenttype/id_service_test.go new file mode 100644 index 00000000000..a6894c67763 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttype/id_service_test.go @@ -0,0 +1,282 @@ +package contenttype + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttype/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/contenttype/method_createorupdate.go new file mode 100644 index 00000000000..d1a48e0857c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttype/method_createorupdate.go @@ -0,0 +1,88 @@ +package contenttype + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ContentTypeContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c ContentTypeClient) CreateOrUpdate(ctx context.Context, id ContentTypeId, input ContentTypeContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 ContentTypeContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttype/method_delete.go b/resource-manager/apimanagement/2024-05-01/contenttype/method_delete.go new file mode 100644 index 00000000000..d3dc044bf5c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttype/method_delete.go @@ -0,0 +1,76 @@ +package contenttype + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c ContentTypeClient) Delete(ctx context.Context, id ContentTypeId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttype/method_get.go b/resource-manager/apimanagement/2024-05-01/contenttype/method_get.go new file mode 100644 index 00000000000..059c81af9e8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttype/method_get.go @@ -0,0 +1,54 @@ +package contenttype + +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 *ContentTypeContract +} + +// Get ... +func (c ContentTypeClient) Get(ctx context.Context, id ContentTypeId) (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 ContentTypeContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttype/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/contenttype/method_listbyservice.go new file mode 100644 index 00000000000..e8b77a15ea7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttype/method_listbyservice.go @@ -0,0 +1,105 @@ +package contenttype + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ContentTypeContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ContentTypeContract +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c ContentTypeClient) ListByService(ctx context.Context, id ServiceId) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/contentTypes", 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 *[]ContentTypeContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c ContentTypeClient) ListByServiceComplete(ctx context.Context, id ServiceId) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, ContentTypeContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ContentTypeClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, predicate ContentTypeContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]ContentTypeContract, 0) + + resp, err := c.ListByService(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttype/model_contenttypecontract.go b/resource-manager/apimanagement/2024-05-01/contenttype/model_contenttypecontract.go new file mode 100644 index 00000000000..dbc795f7525 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttype/model_contenttypecontract.go @@ -0,0 +1,11 @@ +package contenttype + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContentTypeContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ContentTypeContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttype/model_contenttypecontractproperties.go b/resource-manager/apimanagement/2024-05-01/contenttype/model_contenttypecontractproperties.go new file mode 100644 index 00000000000..15c62966fda --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttype/model_contenttypecontractproperties.go @@ -0,0 +1,12 @@ +package contenttype + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContentTypeContractProperties struct { + Description *string `json:"description,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Schema *interface{} `json:"schema,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttype/predicates.go b/resource-manager/apimanagement/2024-05-01/contenttype/predicates.go new file mode 100644 index 00000000000..a2af0a3d264 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttype/predicates.go @@ -0,0 +1,27 @@ +package contenttype + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContentTypeContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ContentTypeContractOperationPredicate) Matches(input ContentTypeContract) 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/apimanagement/2024-05-01/contenttype/version.go b/resource-manager/apimanagement/2024-05-01/contenttype/version.go new file mode 100644 index 00000000000..b5f5b3ee88e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttype/version.go @@ -0,0 +1,12 @@ +package contenttype + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/contenttype/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/README.md b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/README.md new file mode 100644 index 00000000000..d96f1e48212 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/README.md @@ -0,0 +1,106 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/contenttypecontentitem` Documentation + +The `contenttypecontentitem` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/contenttypecontentitem" +``` + + +### Client Initialization + +```go +client := contenttypecontentitem.NewContentTypeContentItemClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ContentTypeContentItemClient.ContentItemCreateOrUpdate` + +```go +ctx := context.TODO() +id := contenttypecontentitem.NewContentItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "contentTypeIdValue", "contentItemIdValue") + +payload := contenttypecontentitem.ContentItemContract{ + // ... +} + + +read, err := client.ContentItemCreateOrUpdate(ctx, id, payload, contenttypecontentitem.DefaultContentItemCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContentTypeContentItemClient.ContentItemDelete` + +```go +ctx := context.TODO() +id := contenttypecontentitem.NewContentItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "contentTypeIdValue", "contentItemIdValue") + +read, err := client.ContentItemDelete(ctx, id, contenttypecontentitem.DefaultContentItemDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContentTypeContentItemClient.ContentItemGet` + +```go +ctx := context.TODO() +id := contenttypecontentitem.NewContentItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "contentTypeIdValue", "contentItemIdValue") + +read, err := client.ContentItemGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContentTypeContentItemClient.ContentItemGetEntityTag` + +```go +ctx := context.TODO() +id := contenttypecontentitem.NewContentItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "contentTypeIdValue", "contentItemIdValue") + +read, err := client.ContentItemGetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContentTypeContentItemClient.ContentItemListByService` + +```go +ctx := context.TODO() +id := contenttypecontentitem.NewContentTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "contentTypeIdValue") + +// alternatively `client.ContentItemListByService(ctx, id)` can be used to do batched pagination +items, err := client.ContentItemListByServiceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/client.go b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/client.go new file mode 100644 index 00000000000..81fef8be029 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/client.go @@ -0,0 +1,26 @@ +package contenttypecontentitem + +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 ContentTypeContentItemClient struct { + Client *resourcemanager.Client +} + +func NewContentTypeContentItemClientWithBaseURI(sdkApi sdkEnv.Api) (*ContentTypeContentItemClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "contenttypecontentitem", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ContentTypeContentItemClient: %+v", err) + } + + return &ContentTypeContentItemClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/id_contentitem.go b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/id_contentitem.go new file mode 100644 index 00000000000..b304e9fdf2b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/id_contentitem.go @@ -0,0 +1,148 @@ +package contenttypecontentitem + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ContentItemId{}) +} + +var _ resourceids.ResourceId = &ContentItemId{} + +// ContentItemId is a struct representing the Resource ID for a Content Item +type ContentItemId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ContentTypeId string + ContentItemId string +} + +// NewContentItemID returns a new ContentItemId struct +func NewContentItemID(subscriptionId string, resourceGroupName string, serviceName string, contentTypeId string, contentItemId string) ContentItemId { + return ContentItemId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ContentTypeId: contentTypeId, + ContentItemId: contentItemId, + } +} + +// ParseContentItemID parses 'input' into a ContentItemId +func ParseContentItemID(input string) (*ContentItemId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContentItemId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContentItemId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseContentItemIDInsensitively parses 'input' case-insensitively into a ContentItemId +// note: this method should only be used for API response data and not user input +func ParseContentItemIDInsensitively(input string) (*ContentItemId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContentItemId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContentItemId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ContentItemId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ContentTypeId, ok = input.Parsed["contentTypeId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "contentTypeId", input) + } + + if id.ContentItemId, ok = input.Parsed["contentItemId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "contentItemId", input) + } + + return nil +} + +// ValidateContentItemID checks that 'input' can be parsed as a Content Item ID +func ValidateContentItemID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseContentItemID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Content Item ID +func (id ContentItemId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/contentTypes/%s/contentItems/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ContentTypeId, id.ContentItemId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Content Item ID +func (id ContentItemId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticContentTypes", "contentTypes", "contentTypes"), + resourceids.UserSpecifiedSegment("contentTypeId", "contentTypeIdValue"), + resourceids.StaticSegment("staticContentItems", "contentItems", "contentItems"), + resourceids.UserSpecifiedSegment("contentItemId", "contentItemIdValue"), + } +} + +// String returns a human-readable description of this Content Item ID +func (id ContentItemId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Content Type: %q", id.ContentTypeId), + fmt.Sprintf("Content Item: %q", id.ContentItemId), + } + return fmt.Sprintf("Content Item (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/id_contentitem_test.go b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/id_contentitem_test.go new file mode 100644 index 00000000000..11b0a6ba6c5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/id_contentitem_test.go @@ -0,0 +1,372 @@ +package contenttypecontentitem + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ContentItemId{} + +func TestNewContentItemID(t *testing.T) { + id := NewContentItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "contentTypeIdValue", "contentItemIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ContentTypeId != "contentTypeIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ContentTypeId'", id.ContentTypeId, "contentTypeIdValue") + } + + if id.ContentItemId != "contentItemIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ContentItemId'", id.ContentItemId, "contentItemIdValue") + } +} + +func TestFormatContentItemID(t *testing.T) { + actual := NewContentItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "contentTypeIdValue", "contentItemIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes/contentTypeIdValue/contentItems/contentItemIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseContentItemID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContentItemId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes/contentTypeIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes/contentTypeIdValue/contentItems", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes/contentTypeIdValue/contentItems/contentItemIdValue", + Expected: &ContentItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ContentTypeId: "contentTypeIdValue", + ContentItemId: "contentItemIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes/contentTypeIdValue/contentItems/contentItemIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContentItemID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ContentTypeId != v.Expected.ContentTypeId { + t.Fatalf("Expected %q but got %q for ContentTypeId", v.Expected.ContentTypeId, actual.ContentTypeId) + } + + if actual.ContentItemId != v.Expected.ContentItemId { + t.Fatalf("Expected %q but got %q for ContentItemId", v.Expected.ContentItemId, actual.ContentItemId) + } + + } +} + +func TestParseContentItemIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContentItemId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/cOnTeNtTyPeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes/contentTypeIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/cOnTeNtTyPeS/cOnTeNtTyPeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes/contentTypeIdValue/contentItems", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/cOnTeNtTyPeS/cOnTeNtTyPeIdVaLuE/cOnTeNtItEmS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes/contentTypeIdValue/contentItems/contentItemIdValue", + Expected: &ContentItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ContentTypeId: "contentTypeIdValue", + ContentItemId: "contentItemIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes/contentTypeIdValue/contentItems/contentItemIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/cOnTeNtTyPeS/cOnTeNtTyPeIdVaLuE/cOnTeNtItEmS/cOnTeNtItEmIdVaLuE", + Expected: &ContentItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ContentTypeId: "cOnTeNtTyPeIdVaLuE", + ContentItemId: "cOnTeNtItEmIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/cOnTeNtTyPeS/cOnTeNtTyPeIdVaLuE/cOnTeNtItEmS/cOnTeNtItEmIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContentItemIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ContentTypeId != v.Expected.ContentTypeId { + t.Fatalf("Expected %q but got %q for ContentTypeId", v.Expected.ContentTypeId, actual.ContentTypeId) + } + + if actual.ContentItemId != v.Expected.ContentItemId { + t.Fatalf("Expected %q but got %q for ContentItemId", v.Expected.ContentItemId, actual.ContentItemId) + } + + } +} + +func TestSegmentsForContentItemId(t *testing.T) { + segments := ContentItemId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ContentItemId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/id_contenttype.go b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/id_contenttype.go new file mode 100644 index 00000000000..576b6390d40 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/id_contenttype.go @@ -0,0 +1,139 @@ +package contenttypecontentitem + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ContentTypeId{}) +} + +var _ resourceids.ResourceId = &ContentTypeId{} + +// ContentTypeId is a struct representing the Resource ID for a Content Type +type ContentTypeId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ContentTypeId string +} + +// NewContentTypeID returns a new ContentTypeId struct +func NewContentTypeID(subscriptionId string, resourceGroupName string, serviceName string, contentTypeId string) ContentTypeId { + return ContentTypeId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ContentTypeId: contentTypeId, + } +} + +// ParseContentTypeID parses 'input' into a ContentTypeId +func ParseContentTypeID(input string) (*ContentTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContentTypeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContentTypeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseContentTypeIDInsensitively parses 'input' case-insensitively into a ContentTypeId +// note: this method should only be used for API response data and not user input +func ParseContentTypeIDInsensitively(input string) (*ContentTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContentTypeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContentTypeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ContentTypeId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ContentTypeId, ok = input.Parsed["contentTypeId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "contentTypeId", input) + } + + return nil +} + +// ValidateContentTypeID checks that 'input' can be parsed as a Content Type ID +func ValidateContentTypeID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseContentTypeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Content Type ID +func (id ContentTypeId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/contentTypes/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ContentTypeId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Content Type ID +func (id ContentTypeId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticContentTypes", "contentTypes", "contentTypes"), + resourceids.UserSpecifiedSegment("contentTypeId", "contentTypeIdValue"), + } +} + +// String returns a human-readable description of this Content Type ID +func (id ContentTypeId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Content Type: %q", id.ContentTypeId), + } + return fmt.Sprintf("Content Type (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/id_contenttype_test.go b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/id_contenttype_test.go new file mode 100644 index 00000000000..69b0bb74287 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/id_contenttype_test.go @@ -0,0 +1,327 @@ +package contenttypecontentitem + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ContentTypeId{} + +func TestNewContentTypeID(t *testing.T) { + id := NewContentTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "contentTypeIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ContentTypeId != "contentTypeIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ContentTypeId'", id.ContentTypeId, "contentTypeIdValue") + } +} + +func TestFormatContentTypeID(t *testing.T) { + actual := NewContentTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "contentTypeIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes/contentTypeIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseContentTypeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContentTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes/contentTypeIdValue", + Expected: &ContentTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ContentTypeId: "contentTypeIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes/contentTypeIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContentTypeID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ContentTypeId != v.Expected.ContentTypeId { + t.Fatalf("Expected %q but got %q for ContentTypeId", v.Expected.ContentTypeId, actual.ContentTypeId) + } + + } +} + +func TestParseContentTypeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContentTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/cOnTeNtTyPeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes/contentTypeIdValue", + Expected: &ContentTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ContentTypeId: "contentTypeIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/contentTypes/contentTypeIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/cOnTeNtTyPeS/cOnTeNtTyPeIdVaLuE", + Expected: &ContentTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ContentTypeId: "cOnTeNtTyPeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/cOnTeNtTyPeS/cOnTeNtTyPeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContentTypeIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ContentTypeId != v.Expected.ContentTypeId { + t.Fatalf("Expected %q but got %q for ContentTypeId", v.Expected.ContentTypeId, actual.ContentTypeId) + } + + } +} + +func TestSegmentsForContentTypeId(t *testing.T) { + segments := ContentTypeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ContentTypeId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/method_contentitemcreateorupdate.go b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/method_contentitemcreateorupdate.go new file mode 100644 index 00000000000..c23ccc2fcb2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/method_contentitemcreateorupdate.go @@ -0,0 +1,88 @@ +package contenttypecontentitem + +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 ContentItemCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ContentItemContract +} + +type ContentItemCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultContentItemCreateOrUpdateOperationOptions() ContentItemCreateOrUpdateOperationOptions { + return ContentItemCreateOrUpdateOperationOptions{} +} + +func (o ContentItemCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o ContentItemCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ContentItemCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// ContentItemCreateOrUpdate ... +func (c ContentTypeContentItemClient) ContentItemCreateOrUpdate(ctx context.Context, id ContentItemId, input ContentItemContract, options ContentItemCreateOrUpdateOperationOptions) (result ContentItemCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 ContentItemContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/method_contentitemdelete.go b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/method_contentitemdelete.go new file mode 100644 index 00000000000..ae0888ce9e8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/method_contentitemdelete.go @@ -0,0 +1,76 @@ +package contenttypecontentitem + +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 ContentItemDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type ContentItemDeleteOperationOptions struct { + IfMatch *string +} + +func DefaultContentItemDeleteOperationOptions() ContentItemDeleteOperationOptions { + return ContentItemDeleteOperationOptions{} +} + +func (o ContentItemDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o ContentItemDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ContentItemDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// ContentItemDelete ... +func (c ContentTypeContentItemClient) ContentItemDelete(ctx context.Context, id ContentItemId, options ContentItemDeleteOperationOptions) (result ContentItemDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/method_contentitemget.go b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/method_contentitemget.go new file mode 100644 index 00000000000..41ca4d59a44 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/method_contentitemget.go @@ -0,0 +1,54 @@ +package contenttypecontentitem + +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 ContentItemGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ContentItemContract +} + +// ContentItemGet ... +func (c ContentTypeContentItemClient) ContentItemGet(ctx context.Context, id ContentItemId) (result ContentItemGetOperationResponse, 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 ContentItemContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/method_contentitemgetentitytag.go b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/method_contentitemgetentitytag.go new file mode 100644 index 00000000000..072a373e255 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/method_contentitemgetentitytag.go @@ -0,0 +1,46 @@ +package contenttypecontentitem + +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 ContentItemGetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// ContentItemGetEntityTag ... +func (c ContentTypeContentItemClient) ContentItemGetEntityTag(ctx context.Context, id ContentItemId) (result ContentItemGetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/method_contentitemlistbyservice.go b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/method_contentitemlistbyservice.go new file mode 100644 index 00000000000..c9e59da0d4b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/method_contentitemlistbyservice.go @@ -0,0 +1,105 @@ +package contenttypecontentitem + +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 ContentItemListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ContentItemContract +} + +type ContentItemListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ContentItemContract +} + +type ContentItemListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ContentItemListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ContentItemListByService ... +func (c ContentTypeContentItemClient) ContentItemListByService(ctx context.Context, id ContentTypeId) (result ContentItemListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ContentItemListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/contentItems", 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 *[]ContentItemContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ContentItemListByServiceComplete retrieves all the results into a single object +func (c ContentTypeContentItemClient) ContentItemListByServiceComplete(ctx context.Context, id ContentTypeId) (ContentItemListByServiceCompleteResult, error) { + return c.ContentItemListByServiceCompleteMatchingPredicate(ctx, id, ContentItemContractOperationPredicate{}) +} + +// ContentItemListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ContentTypeContentItemClient) ContentItemListByServiceCompleteMatchingPredicate(ctx context.Context, id ContentTypeId, predicate ContentItemContractOperationPredicate) (result ContentItemListByServiceCompleteResult, err error) { + items := make([]ContentItemContract, 0) + + resp, err := c.ContentItemListByService(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ContentItemListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/model_contentitemcontract.go b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/model_contentitemcontract.go new file mode 100644 index 00000000000..d2a4e711fb4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/model_contentitemcontract.go @@ -0,0 +1,11 @@ +package contenttypecontentitem + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContentItemContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *interface{} `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/predicates.go b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/predicates.go new file mode 100644 index 00000000000..4fe5ffb1fe9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/predicates.go @@ -0,0 +1,32 @@ +package contenttypecontentitem + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContentItemContractOperationPredicate struct { + Id *string + Name *string + Properties *interface{} + Type *string +} + +func (p ContentItemContractOperationPredicate) Matches(input ContentItemContract) 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.Properties != nil && (input.Properties == nil || *p.Properties != *input.Properties) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/version.go b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/version.go new file mode 100644 index 00000000000..f4c700c2ae4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/contenttypecontentitem/version.go @@ -0,0 +1,12 @@ +package contenttypecontentitem + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/contenttypecontentitem/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/delegationsettings/README.md b/resource-manager/apimanagement/2024-05-01/delegationsettings/README.md new file mode 100644 index 00000000000..db1aff49f69 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/delegationsettings/README.md @@ -0,0 +1,110 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/delegationsettings` Documentation + +The `delegationsettings` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/delegationsettings" +``` + + +### Client Initialization + +```go +client := delegationsettings.NewDelegationSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DelegationSettingsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := delegationsettings.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +payload := delegationsettings.PortalDelegationSettings{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, delegationsettings.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DelegationSettingsClient.Get` + +```go +ctx := context.TODO() +id := delegationsettings.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +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: `DelegationSettingsClient.GetEntityTag` + +```go +ctx := context.TODO() +id := delegationsettings.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DelegationSettingsClient.ListSecrets` + +```go +ctx := context.TODO() +id := delegationsettings.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +read, err := client.ListSecrets(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DelegationSettingsClient.Update` + +```go +ctx := context.TODO() +id := delegationsettings.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +payload := delegationsettings.PortalDelegationSettings{ + // ... +} + + +read, err := client.Update(ctx, id, payload, delegationsettings.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/delegationsettings/client.go b/resource-manager/apimanagement/2024-05-01/delegationsettings/client.go new file mode 100644 index 00000000000..975a55a7a10 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/delegationsettings/client.go @@ -0,0 +1,26 @@ +package delegationsettings + +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 DelegationSettingsClient struct { + Client *resourcemanager.Client +} + +func NewDelegationSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*DelegationSettingsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "delegationsettings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DelegationSettingsClient: %+v", err) + } + + return &DelegationSettingsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/delegationsettings/id_service.go b/resource-manager/apimanagement/2024-05-01/delegationsettings/id_service.go new file mode 100644 index 00000000000..c3aca641d8f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/delegationsettings/id_service.go @@ -0,0 +1,130 @@ +package delegationsettings + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/delegationsettings/id_service_test.go b/resource-manager/apimanagement/2024-05-01/delegationsettings/id_service_test.go new file mode 100644 index 00000000000..185200cda56 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/delegationsettings/id_service_test.go @@ -0,0 +1,282 @@ +package delegationsettings + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/delegationsettings/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/delegationsettings/method_createorupdate.go new file mode 100644 index 00000000000..194af96a592 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/delegationsettings/method_createorupdate.go @@ -0,0 +1,87 @@ +package delegationsettings + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PortalDelegationSettings +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c DelegationSettingsClient) CreateOrUpdate(ctx context.Context, id ServiceId, input PortalDelegationSettings, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + Path: fmt.Sprintf("%s/portalsettings/delegation", 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 PortalDelegationSettings + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/delegationsettings/method_get.go b/resource-manager/apimanagement/2024-05-01/delegationsettings/method_get.go new file mode 100644 index 00000000000..db02f9407db --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/delegationsettings/method_get.go @@ -0,0 +1,55 @@ +package delegationsettings + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PortalDelegationSettings +} + +// Get ... +func (c DelegationSettingsClient) Get(ctx context.Context, id ServiceId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/portalsettings/delegation", 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 PortalDelegationSettings + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/delegationsettings/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/delegationsettings/method_getentitytag.go new file mode 100644 index 00000000000..6d1fc5745c7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/delegationsettings/method_getentitytag.go @@ -0,0 +1,47 @@ +package delegationsettings + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c DelegationSettingsClient) GetEntityTag(ctx context.Context, id ServiceId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: fmt.Sprintf("%s/portalsettings/delegation", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/delegationsettings/method_listsecrets.go b/resource-manager/apimanagement/2024-05-01/delegationsettings/method_listsecrets.go new file mode 100644 index 00000000000..50ee5bed1bd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/delegationsettings/method_listsecrets.go @@ -0,0 +1,55 @@ +package delegationsettings + +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 ListSecretsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PortalSettingValidationKeyContract +} + +// ListSecrets ... +func (c DelegationSettingsClient) ListSecrets(ctx context.Context, id ServiceId) (result ListSecretsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/portalsettings/delegation/listSecrets", 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 PortalSettingValidationKeyContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/delegationsettings/method_update.go b/resource-manager/apimanagement/2024-05-01/delegationsettings/method_update.go new file mode 100644 index 00000000000..c010e8ee865 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/delegationsettings/method_update.go @@ -0,0 +1,79 @@ +package delegationsettings + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c DelegationSettingsClient) Update(ctx context.Context, id ServiceId, input PortalDelegationSettings, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + Path: fmt.Sprintf("%s/portalsettings/delegation", 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/apimanagement/2024-05-01/delegationsettings/model_portaldelegationsettings.go b/resource-manager/apimanagement/2024-05-01/delegationsettings/model_portaldelegationsettings.go new file mode 100644 index 00000000000..5ae7e1afcf1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/delegationsettings/model_portaldelegationsettings.go @@ -0,0 +1,11 @@ +package delegationsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PortalDelegationSettings struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PortalDelegationSettingsProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/delegationsettings/model_portaldelegationsettingsproperties.go b/resource-manager/apimanagement/2024-05-01/delegationsettings/model_portaldelegationsettingsproperties.go new file mode 100644 index 00000000000..e15507944d5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/delegationsettings/model_portaldelegationsettingsproperties.go @@ -0,0 +1,11 @@ +package delegationsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PortalDelegationSettingsProperties struct { + Subscriptions *SubscriptionsDelegationSettingsProperties `json:"subscriptions,omitempty"` + Url *string `json:"url,omitempty"` + UserRegistration *RegistrationDelegationSettingsProperties `json:"userRegistration,omitempty"` + ValidationKey *string `json:"validationKey,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/delegationsettings/model_portalsettingvalidationkeycontract.go b/resource-manager/apimanagement/2024-05-01/delegationsettings/model_portalsettingvalidationkeycontract.go new file mode 100644 index 00000000000..a9c04e71e68 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/delegationsettings/model_portalsettingvalidationkeycontract.go @@ -0,0 +1,8 @@ +package delegationsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PortalSettingValidationKeyContract struct { + ValidationKey *string `json:"validationKey,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/delegationsettings/model_registrationdelegationsettingsproperties.go b/resource-manager/apimanagement/2024-05-01/delegationsettings/model_registrationdelegationsettingsproperties.go new file mode 100644 index 00000000000..6b440ac2f19 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/delegationsettings/model_registrationdelegationsettingsproperties.go @@ -0,0 +1,8 @@ +package delegationsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegistrationDelegationSettingsProperties struct { + Enabled *bool `json:"enabled,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/delegationsettings/model_subscriptionsdelegationsettingsproperties.go b/resource-manager/apimanagement/2024-05-01/delegationsettings/model_subscriptionsdelegationsettingsproperties.go new file mode 100644 index 00000000000..4d1c8e581a7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/delegationsettings/model_subscriptionsdelegationsettingsproperties.go @@ -0,0 +1,8 @@ +package delegationsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionsDelegationSettingsProperties struct { + Enabled *bool `json:"enabled,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/delegationsettings/version.go b/resource-manager/apimanagement/2024-05-01/delegationsettings/version.go new file mode 100644 index 00000000000..dc75d0cacde --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/delegationsettings/version.go @@ -0,0 +1,12 @@ +package delegationsettings + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/delegationsettings/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/deletedservice/README.md b/resource-manager/apimanagement/2024-05-01/deletedservice/README.md new file mode 100644 index 00000000000..3df5c2ac618 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/deletedservice/README.md @@ -0,0 +1,66 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/deletedservice` Documentation + +The `deletedservice` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/deletedservice" +``` + + +### Client Initialization + +```go +client := deletedservice.NewDeletedServiceClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DeletedServiceClient.GetByName` + +```go +ctx := context.TODO() +id := deletedservice.NewDeletedServiceID("12345678-1234-9876-4563-123456789012", "locationValue", "deletedServiceValue") + +read, err := client.GetByName(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeletedServiceClient.ListBySubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id)` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DeletedServiceClient.Purge` + +```go +ctx := context.TODO() +id := deletedservice.NewDeletedServiceID("12345678-1234-9876-4563-123456789012", "locationValue", "deletedServiceValue") + +if err := client.PurgeThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/deletedservice/client.go b/resource-manager/apimanagement/2024-05-01/deletedservice/client.go new file mode 100644 index 00000000000..7ce116a7259 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/deletedservice/client.go @@ -0,0 +1,26 @@ +package deletedservice + +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 DeletedServiceClient struct { + Client *resourcemanager.Client +} + +func NewDeletedServiceClientWithBaseURI(sdkApi sdkEnv.Api) (*DeletedServiceClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "deletedservice", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DeletedServiceClient: %+v", err) + } + + return &DeletedServiceClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/deletedservice/id_deletedservice.go b/resource-manager/apimanagement/2024-05-01/deletedservice/id_deletedservice.go new file mode 100644 index 00000000000..d4f9feb3f31 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/deletedservice/id_deletedservice.go @@ -0,0 +1,130 @@ +package deletedservice + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DeletedServiceId{}) +} + +var _ resourceids.ResourceId = &DeletedServiceId{} + +// DeletedServiceId is a struct representing the Resource ID for a Deleted Service +type DeletedServiceId struct { + SubscriptionId string + LocationName string + DeletedServiceName string +} + +// NewDeletedServiceID returns a new DeletedServiceId struct +func NewDeletedServiceID(subscriptionId string, locationName string, deletedServiceName string) DeletedServiceId { + return DeletedServiceId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + DeletedServiceName: deletedServiceName, + } +} + +// ParseDeletedServiceID parses 'input' into a DeletedServiceId +func ParseDeletedServiceID(input string) (*DeletedServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeletedServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeletedServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDeletedServiceIDInsensitively parses 'input' case-insensitively into a DeletedServiceId +// note: this method should only be used for API response data and not user input +func ParseDeletedServiceIDInsensitively(input string) (*DeletedServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeletedServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeletedServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DeletedServiceId) 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.DeletedServiceName, ok = input.Parsed["deletedServiceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deletedServiceName", input) + } + + return nil +} + +// ValidateDeletedServiceID checks that 'input' can be parsed as a Deleted Service ID +func ValidateDeletedServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseDeletedServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Deleted Service ID +func (id DeletedServiceId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.ApiManagement/locations/%s/deletedServices/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName, id.DeletedServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Deleted Service ID +func (id DeletedServiceId) 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("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationValue"), + resourceids.StaticSegment("staticDeletedServices", "deletedServices", "deletedServices"), + resourceids.UserSpecifiedSegment("deletedServiceName", "deletedServiceValue"), + } +} + +// String returns a human-readable description of this Deleted Service ID +func (id DeletedServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Deleted Service Name: %q", id.DeletedServiceName), + } + return fmt.Sprintf("Deleted Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/deletedservice/id_deletedservice_test.go b/resource-manager/apimanagement/2024-05-01/deletedservice/id_deletedservice_test.go new file mode 100644 index 00000000000..2451cae32c4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/deletedservice/id_deletedservice_test.go @@ -0,0 +1,282 @@ +package deletedservice + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &DeletedServiceId{} + +func TestNewDeletedServiceID(t *testing.T) { + id := NewDeletedServiceID("12345678-1234-9876-4563-123456789012", "locationValue", "deletedServiceValue") + + if id.SubscriptionId != "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.DeletedServiceName != "deletedServiceValue" { + t.Fatalf("Expected %q but got %q for Segment 'DeletedServiceName'", id.DeletedServiceName, "deletedServiceValue") + } +} + +func TestFormatDeletedServiceID(t *testing.T) { + actual := NewDeletedServiceID("12345678-1234-9876-4563-123456789012", "locationValue", "deletedServiceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.ApiManagement/locations/locationValue/deletedServices/deletedServiceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDeletedServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeletedServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + 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.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.ApiManagement/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.ApiManagement/locations/locationValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.ApiManagement/locations/locationValue/deletedServices", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.ApiManagement/locations/locationValue/deletedServices/deletedServiceValue", + Expected: &DeletedServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + DeletedServiceName: "deletedServiceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.ApiManagement/locations/locationValue/deletedServices/deletedServiceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeletedServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't 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.DeletedServiceName != v.Expected.DeletedServiceName { + t.Fatalf("Expected %q but got %q for DeletedServiceName", v.Expected.DeletedServiceName, actual.DeletedServiceName) + } + + } +} + +func TestParseDeletedServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeletedServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (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.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.ApiManagement/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.ApiManagement/locations/locationValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/lOcAtIoNs/lOcAtIoNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.ApiManagement/locations/locationValue/deletedServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/lOcAtIoNs/lOcAtIoNvAlUe/dElEtEdSeRvIcEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.ApiManagement/locations/locationValue/deletedServices/deletedServiceValue", + Expected: &DeletedServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + DeletedServiceName: "deletedServiceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.ApiManagement/locations/locationValue/deletedServices/deletedServiceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/lOcAtIoNs/lOcAtIoNvAlUe/dElEtEdSeRvIcEs/dElEtEdSeRvIcEvAlUe", + Expected: &DeletedServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNvAlUe", + DeletedServiceName: "dElEtEdSeRvIcEvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/lOcAtIoNs/lOcAtIoNvAlUe/dElEtEdSeRvIcEs/dElEtEdSeRvIcEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeletedServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't 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.DeletedServiceName != v.Expected.DeletedServiceName { + t.Fatalf("Expected %q but got %q for DeletedServiceName", v.Expected.DeletedServiceName, actual.DeletedServiceName) + } + + } +} + +func TestSegmentsForDeletedServiceId(t *testing.T) { + segments := DeletedServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DeletedServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/deletedservice/method_getbyname.go b/resource-manager/apimanagement/2024-05-01/deletedservice/method_getbyname.go new file mode 100644 index 00000000000..f7fef324399 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/deletedservice/method_getbyname.go @@ -0,0 +1,54 @@ +package deletedservice + +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 GetByNameOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeletedServiceContract +} + +// GetByName ... +func (c DeletedServiceClient) GetByName(ctx context.Context, id DeletedServiceId) (result GetByNameOperationResponse, 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 DeletedServiceContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/deletedservice/method_listbysubscription.go b/resource-manager/apimanagement/2024-05-01/deletedservice/method_listbysubscription.go new file mode 100644 index 00000000000..5eed8b3bffd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/deletedservice/method_listbysubscription.go @@ -0,0 +1,106 @@ +package deletedservice + +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 *[]DeletedServiceContract +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []DeletedServiceContract +} + +type ListBySubscriptionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySubscriptionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySubscription ... +func (c DeletedServiceClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListBySubscriptionCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.ApiManagement/deletedServices", 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 *[]DeletedServiceContract `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 DeletedServiceClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, DeletedServiceContractOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DeletedServiceClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate DeletedServiceContractOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]DeletedServiceContract, 0) + + resp, err := c.ListBySubscription(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/deletedservice/method_purge.go b/resource-manager/apimanagement/2024-05-01/deletedservice/method_purge.go new file mode 100644 index 00000000000..0bdd2b189a2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/deletedservice/method_purge.go @@ -0,0 +1,72 @@ +package deletedservice + +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 PurgeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *DeletedServiceContract +} + +// Purge ... +func (c DeletedServiceClient) Purge(ctx context.Context, id DeletedServiceId) (result PurgeOperationResponse, 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 +} + +// PurgeThenPoll performs Purge then polls until it's completed +func (c DeletedServiceClient) PurgeThenPoll(ctx context.Context, id DeletedServiceId) error { + result, err := c.Purge(ctx, id) + if err != nil { + return fmt.Errorf("performing Purge: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Purge: %+v", err) + } + + return nil +} diff --git a/resource-manager/apimanagement/2024-05-01/deletedservice/model_deletedservicecontract.go b/resource-manager/apimanagement/2024-05-01/deletedservice/model_deletedservicecontract.go new file mode 100644 index 00000000000..23d3fd90428 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/deletedservice/model_deletedservicecontract.go @@ -0,0 +1,12 @@ +package deletedservice + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeletedServiceContract struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DeletedServiceContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/deletedservice/model_deletedservicecontractproperties.go b/resource-manager/apimanagement/2024-05-01/deletedservice/model_deletedservicecontractproperties.go new file mode 100644 index 00000000000..3ac7f055ea8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/deletedservice/model_deletedservicecontractproperties.go @@ -0,0 +1,40 @@ +package deletedservice + +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 DeletedServiceContractProperties struct { + DeletionDate *string `json:"deletionDate,omitempty"` + ScheduledPurgeDate *string `json:"scheduledPurgeDate,omitempty"` + ServiceId *string `json:"serviceId,omitempty"` +} + +func (o *DeletedServiceContractProperties) GetDeletionDateAsTime() (*time.Time, error) { + if o.DeletionDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeletionDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *DeletedServiceContractProperties) SetDeletionDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeletionDate = &formatted +} + +func (o *DeletedServiceContractProperties) GetScheduledPurgeDateAsTime() (*time.Time, error) { + if o.ScheduledPurgeDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ScheduledPurgeDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *DeletedServiceContractProperties) SetScheduledPurgeDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ScheduledPurgeDate = &formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/deletedservice/predicates.go b/resource-manager/apimanagement/2024-05-01/deletedservice/predicates.go new file mode 100644 index 00000000000..54bf3b119fb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/deletedservice/predicates.go @@ -0,0 +1,32 @@ +package deletedservice + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeletedServiceContractOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p DeletedServiceContractOperationPredicate) Matches(input DeletedServiceContract) 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/apimanagement/2024-05-01/deletedservice/version.go b/resource-manager/apimanagement/2024-05-01/deletedservice/version.go new file mode 100644 index 00000000000..efca48d0ebd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/deletedservice/version.go @@ -0,0 +1,12 @@ +package deletedservice + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/deletedservice/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/README.md b/resource-manager/apimanagement/2024-05-01/diagnostic/README.md new file mode 100644 index 00000000000..2b984900d7f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/README.md @@ -0,0 +1,234 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/diagnostic` Documentation + +The `diagnostic` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/diagnostic" +``` + + +### Client Initialization + +```go +client := diagnostic.NewDiagnosticClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DiagnosticClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := diagnostic.NewDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "diagnosticIdValue") + +payload := diagnostic.DiagnosticContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, diagnostic.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DiagnosticClient.Delete` + +```go +ctx := context.TODO() +id := diagnostic.NewDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "diagnosticIdValue") + +read, err := client.Delete(ctx, id, diagnostic.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DiagnosticClient.Get` + +```go +ctx := context.TODO() +id := diagnostic.NewDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "diagnosticIdValue") + +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: `DiagnosticClient.GetEntityTag` + +```go +ctx := context.TODO() +id := diagnostic.NewDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "diagnosticIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DiagnosticClient.ListByService` + +```go +ctx := context.TODO() +id := diagnostic.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, diagnostic.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, diagnostic.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DiagnosticClient.Update` + +```go +ctx := context.TODO() +id := diagnostic.NewDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "diagnosticIdValue") + +payload := diagnostic.DiagnosticContract{ + // ... +} + + +read, err := client.Update(ctx, id, payload, diagnostic.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DiagnosticClient.WorkspaceDiagnosticCreateOrUpdate` + +```go +ctx := context.TODO() +id := diagnostic.NewWorkspaceDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "diagnosticIdValue") + +payload := diagnostic.DiagnosticContract{ + // ... +} + + +read, err := client.WorkspaceDiagnosticCreateOrUpdate(ctx, id, payload, diagnostic.DefaultWorkspaceDiagnosticCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DiagnosticClient.WorkspaceDiagnosticDelete` + +```go +ctx := context.TODO() +id := diagnostic.NewWorkspaceDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "diagnosticIdValue") + +read, err := client.WorkspaceDiagnosticDelete(ctx, id, diagnostic.DefaultWorkspaceDiagnosticDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DiagnosticClient.WorkspaceDiagnosticGet` + +```go +ctx := context.TODO() +id := diagnostic.NewWorkspaceDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "diagnosticIdValue") + +read, err := client.WorkspaceDiagnosticGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DiagnosticClient.WorkspaceDiagnosticGetEntityTag` + +```go +ctx := context.TODO() +id := diagnostic.NewWorkspaceDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "diagnosticIdValue") + +read, err := client.WorkspaceDiagnosticGetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DiagnosticClient.WorkspaceDiagnosticListByWorkspace` + +```go +ctx := context.TODO() +id := diagnostic.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +// alternatively `client.WorkspaceDiagnosticListByWorkspace(ctx, id, diagnostic.DefaultWorkspaceDiagnosticListByWorkspaceOperationOptions())` can be used to do batched pagination +items, err := client.WorkspaceDiagnosticListByWorkspaceComplete(ctx, id, diagnostic.DefaultWorkspaceDiagnosticListByWorkspaceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DiagnosticClient.WorkspaceDiagnosticUpdate` + +```go +ctx := context.TODO() +id := diagnostic.NewWorkspaceDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "diagnosticIdValue") + +payload := diagnostic.DiagnosticUpdateContract{ + // ... +} + + +read, err := client.WorkspaceDiagnosticUpdate(ctx, id, payload, diagnostic.DefaultWorkspaceDiagnosticUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/client.go b/resource-manager/apimanagement/2024-05-01/diagnostic/client.go new file mode 100644 index 00000000000..d7b4ed69319 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/client.go @@ -0,0 +1,26 @@ +package diagnostic + +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 DiagnosticClient struct { + Client *resourcemanager.Client +} + +func NewDiagnosticClientWithBaseURI(sdkApi sdkEnv.Api) (*DiagnosticClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "diagnostic", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DiagnosticClient: %+v", err) + } + + return &DiagnosticClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/constants.go b/resource-manager/apimanagement/2024-05-01/diagnostic/constants.go new file mode 100644 index 00000000000..cde4ab74afa --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/constants.go @@ -0,0 +1,256 @@ +package diagnostic + +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 AlwaysLog string + +const ( + AlwaysLogAllErrors AlwaysLog = "allErrors" +) + +func PossibleValuesForAlwaysLog() []string { + return []string{ + string(AlwaysLogAllErrors), + } +} + +func (s *AlwaysLog) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlwaysLog(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlwaysLog(input string) (*AlwaysLog, error) { + vals := map[string]AlwaysLog{ + "allerrors": AlwaysLogAllErrors, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlwaysLog(input) + return &out, nil +} + +type DataMaskingMode string + +const ( + DataMaskingModeHide DataMaskingMode = "Hide" + DataMaskingModeMask DataMaskingMode = "Mask" +) + +func PossibleValuesForDataMaskingMode() []string { + return []string{ + string(DataMaskingModeHide), + string(DataMaskingModeMask), + } +} + +func (s *DataMaskingMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataMaskingMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDataMaskingMode(input string) (*DataMaskingMode, error) { + vals := map[string]DataMaskingMode{ + "hide": DataMaskingModeHide, + "mask": DataMaskingModeMask, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataMaskingMode(input) + return &out, nil +} + +type HTTPCorrelationProtocol string + +const ( + HTTPCorrelationProtocolLegacy HTTPCorrelationProtocol = "Legacy" + HTTPCorrelationProtocolNone HTTPCorrelationProtocol = "None" + HTTPCorrelationProtocolWThreeC HTTPCorrelationProtocol = "W3C" +) + +func PossibleValuesForHTTPCorrelationProtocol() []string { + return []string{ + string(HTTPCorrelationProtocolLegacy), + string(HTTPCorrelationProtocolNone), + string(HTTPCorrelationProtocolWThreeC), + } +} + +func (s *HTTPCorrelationProtocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHTTPCorrelationProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHTTPCorrelationProtocol(input string) (*HTTPCorrelationProtocol, error) { + vals := map[string]HTTPCorrelationProtocol{ + "legacy": HTTPCorrelationProtocolLegacy, + "none": HTTPCorrelationProtocolNone, + "w3c": HTTPCorrelationProtocolWThreeC, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HTTPCorrelationProtocol(input) + return &out, nil +} + +type OperationNameFormat string + +const ( + OperationNameFormatName OperationNameFormat = "Name" + OperationNameFormatUrl OperationNameFormat = "Url" +) + +func PossibleValuesForOperationNameFormat() []string { + return []string{ + string(OperationNameFormatName), + string(OperationNameFormatUrl), + } +} + +func (s *OperationNameFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperationNameFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOperationNameFormat(input string) (*OperationNameFormat, error) { + vals := map[string]OperationNameFormat{ + "name": OperationNameFormatName, + "url": OperationNameFormatUrl, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OperationNameFormat(input) + return &out, nil +} + +type SamplingType string + +const ( + SamplingTypeFixed SamplingType = "fixed" +) + +func PossibleValuesForSamplingType() []string { + return []string{ + string(SamplingTypeFixed), + } +} + +func (s *SamplingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSamplingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSamplingType(input string) (*SamplingType, error) { + vals := map[string]SamplingType{ + "fixed": SamplingTypeFixed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SamplingType(input) + return &out, nil +} + +type Verbosity string + +const ( + VerbosityError Verbosity = "error" + VerbosityInformation Verbosity = "information" + VerbosityVerbose Verbosity = "verbose" +) + +func PossibleValuesForVerbosity() []string { + return []string{ + string(VerbosityError), + string(VerbosityInformation), + string(VerbosityVerbose), + } +} + +func (s *Verbosity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVerbosity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVerbosity(input string) (*Verbosity, error) { + vals := map[string]Verbosity{ + "error": VerbosityError, + "information": VerbosityInformation, + "verbose": VerbosityVerbose, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Verbosity(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/id_diagnostic.go b/resource-manager/apimanagement/2024-05-01/diagnostic/id_diagnostic.go new file mode 100644 index 00000000000..890a40a3e9c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/id_diagnostic.go @@ -0,0 +1,139 @@ +package diagnostic + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DiagnosticId{}) +} + +var _ resourceids.ResourceId = &DiagnosticId{} + +// DiagnosticId is a struct representing the Resource ID for a Diagnostic +type DiagnosticId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + DiagnosticId string +} + +// NewDiagnosticID returns a new DiagnosticId struct +func NewDiagnosticID(subscriptionId string, resourceGroupName string, serviceName string, diagnosticId string) DiagnosticId { + return DiagnosticId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + DiagnosticId: diagnosticId, + } +} + +// ParseDiagnosticID parses 'input' into a DiagnosticId +func ParseDiagnosticID(input string) (*DiagnosticId, error) { + parser := resourceids.NewParserFromResourceIdType(&DiagnosticId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DiagnosticId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDiagnosticIDInsensitively parses 'input' case-insensitively into a DiagnosticId +// note: this method should only be used for API response data and not user input +func ParseDiagnosticIDInsensitively(input string) (*DiagnosticId, error) { + parser := resourceids.NewParserFromResourceIdType(&DiagnosticId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DiagnosticId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DiagnosticId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.DiagnosticId, ok = input.Parsed["diagnosticId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "diagnosticId", input) + } + + return nil +} + +// ValidateDiagnosticID checks that 'input' can be parsed as a Diagnostic ID +func ValidateDiagnosticID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseDiagnosticID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Diagnostic ID +func (id DiagnosticId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/diagnostics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.DiagnosticId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Diagnostic ID +func (id DiagnosticId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticDiagnostics", "diagnostics", "diagnostics"), + resourceids.UserSpecifiedSegment("diagnosticId", "diagnosticIdValue"), + } +} + +// String returns a human-readable description of this Diagnostic ID +func (id DiagnosticId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Diagnostic: %q", id.DiagnosticId), + } + return fmt.Sprintf("Diagnostic (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/id_diagnostic_test.go b/resource-manager/apimanagement/2024-05-01/diagnostic/id_diagnostic_test.go new file mode 100644 index 00000000000..946f6136711 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/id_diagnostic_test.go @@ -0,0 +1,327 @@ +package diagnostic + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &DiagnosticId{} + +func TestNewDiagnosticID(t *testing.T) { + id := NewDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "diagnosticIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.DiagnosticId != "diagnosticIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'DiagnosticId'", id.DiagnosticId, "diagnosticIdValue") + } +} + +func TestFormatDiagnosticID(t *testing.T) { + actual := NewDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "diagnosticIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/diagnostics/diagnosticIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDiagnosticID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DiagnosticId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/diagnostics", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/diagnostics/diagnosticIdValue", + Expected: &DiagnosticId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + DiagnosticId: "diagnosticIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/diagnostics/diagnosticIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDiagnosticID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.DiagnosticId != v.Expected.DiagnosticId { + t.Fatalf("Expected %q but got %q for DiagnosticId", v.Expected.DiagnosticId, actual.DiagnosticId) + } + + } +} + +func TestParseDiagnosticIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DiagnosticId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/diagnostics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/dIaGnOsTiCs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/diagnostics/diagnosticIdValue", + Expected: &DiagnosticId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + DiagnosticId: "diagnosticIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/diagnostics/diagnosticIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/dIaGnOsTiCs/dIaGnOsTiCiDvAlUe", + Expected: &DiagnosticId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + DiagnosticId: "dIaGnOsTiCiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/dIaGnOsTiCs/dIaGnOsTiCiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDiagnosticIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.DiagnosticId != v.Expected.DiagnosticId { + t.Fatalf("Expected %q but got %q for DiagnosticId", v.Expected.DiagnosticId, actual.DiagnosticId) + } + + } +} + +func TestSegmentsForDiagnosticId(t *testing.T) { + segments := DiagnosticId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DiagnosticId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/id_service.go b/resource-manager/apimanagement/2024-05-01/diagnostic/id_service.go new file mode 100644 index 00000000000..ce1adfde374 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/id_service.go @@ -0,0 +1,130 @@ +package diagnostic + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/id_service_test.go b/resource-manager/apimanagement/2024-05-01/diagnostic/id_service_test.go new file mode 100644 index 00000000000..1aa8386d1c5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/id_service_test.go @@ -0,0 +1,282 @@ +package diagnostic + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/id_workspace.go b/resource-manager/apimanagement/2024-05-01/diagnostic/id_workspace.go new file mode 100644 index 00000000000..a8f6a5b0444 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/id_workspace.go @@ -0,0 +1,139 @@ +package diagnostic + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/id_workspace_test.go b/resource-manager/apimanagement/2024-05-01/diagnostic/id_workspace_test.go new file mode 100644 index 00000000000..0444cffbcfa --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/id_workspace_test.go @@ -0,0 +1,327 @@ +package diagnostic + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/id_workspacediagnostic.go b/resource-manager/apimanagement/2024-05-01/diagnostic/id_workspacediagnostic.go new file mode 100644 index 00000000000..93f1dbd01ec --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/id_workspacediagnostic.go @@ -0,0 +1,148 @@ +package diagnostic + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceDiagnosticId{}) +} + +var _ resourceids.ResourceId = &WorkspaceDiagnosticId{} + +// WorkspaceDiagnosticId is a struct representing the Resource ID for a Workspace Diagnostic +type WorkspaceDiagnosticId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + DiagnosticId string +} + +// NewWorkspaceDiagnosticID returns a new WorkspaceDiagnosticId struct +func NewWorkspaceDiagnosticID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, diagnosticId string) WorkspaceDiagnosticId { + return WorkspaceDiagnosticId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + DiagnosticId: diagnosticId, + } +} + +// ParseWorkspaceDiagnosticID parses 'input' into a WorkspaceDiagnosticId +func ParseWorkspaceDiagnosticID(input string) (*WorkspaceDiagnosticId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceDiagnosticId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceDiagnosticId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceDiagnosticIDInsensitively parses 'input' case-insensitively into a WorkspaceDiagnosticId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceDiagnosticIDInsensitively(input string) (*WorkspaceDiagnosticId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceDiagnosticId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceDiagnosticId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceDiagnosticId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.DiagnosticId, ok = input.Parsed["diagnosticId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "diagnosticId", input) + } + + return nil +} + +// ValidateWorkspaceDiagnosticID checks that 'input' can be parsed as a Workspace Diagnostic ID +func ValidateWorkspaceDiagnosticID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceDiagnosticID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Diagnostic ID +func (id WorkspaceDiagnosticId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/diagnostics/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.DiagnosticId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Diagnostic ID +func (id WorkspaceDiagnosticId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticDiagnostics", "diagnostics", "diagnostics"), + resourceids.UserSpecifiedSegment("diagnosticId", "diagnosticIdValue"), + } +} + +// String returns a human-readable description of this Workspace Diagnostic ID +func (id WorkspaceDiagnosticId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Diagnostic: %q", id.DiagnosticId), + } + return fmt.Sprintf("Workspace Diagnostic (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/id_workspacediagnostic_test.go b/resource-manager/apimanagement/2024-05-01/diagnostic/id_workspacediagnostic_test.go new file mode 100644 index 00000000000..8ebdb3761a4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/id_workspacediagnostic_test.go @@ -0,0 +1,372 @@ +package diagnostic + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceDiagnosticId{} + +func TestNewWorkspaceDiagnosticID(t *testing.T) { + id := NewWorkspaceDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "diagnosticIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.DiagnosticId != "diagnosticIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'DiagnosticId'", id.DiagnosticId, "diagnosticIdValue") + } +} + +func TestFormatWorkspaceDiagnosticID(t *testing.T) { + actual := NewWorkspaceDiagnosticID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "diagnosticIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/diagnostics/diagnosticIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceDiagnosticID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceDiagnosticId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/diagnostics", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/diagnostics/diagnosticIdValue", + Expected: &WorkspaceDiagnosticId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + DiagnosticId: "diagnosticIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/diagnostics/diagnosticIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceDiagnosticID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.DiagnosticId != v.Expected.DiagnosticId { + t.Fatalf("Expected %q but got %q for DiagnosticId", v.Expected.DiagnosticId, actual.DiagnosticId) + } + + } +} + +func TestParseWorkspaceDiagnosticIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceDiagnosticId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/diagnostics", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/dIaGnOsTiCs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/diagnostics/diagnosticIdValue", + Expected: &WorkspaceDiagnosticId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + DiagnosticId: "diagnosticIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/diagnostics/diagnosticIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/dIaGnOsTiCs/dIaGnOsTiCiDvAlUe", + Expected: &WorkspaceDiagnosticId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + DiagnosticId: "dIaGnOsTiCiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/dIaGnOsTiCs/dIaGnOsTiCiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceDiagnosticIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.DiagnosticId != v.Expected.DiagnosticId { + t.Fatalf("Expected %q but got %q for DiagnosticId", v.Expected.DiagnosticId, actual.DiagnosticId) + } + + } +} + +func TestSegmentsForWorkspaceDiagnosticId(t *testing.T) { + segments := WorkspaceDiagnosticId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceDiagnosticId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/diagnostic/method_createorupdate.go new file mode 100644 index 00000000000..63709e2900a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/method_createorupdate.go @@ -0,0 +1,88 @@ +package diagnostic + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DiagnosticContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c DiagnosticClient) CreateOrUpdate(ctx context.Context, id DiagnosticId, input DiagnosticContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 DiagnosticContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/method_delete.go b/resource-manager/apimanagement/2024-05-01/diagnostic/method_delete.go new file mode 100644 index 00000000000..4f5b2bc7d55 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/method_delete.go @@ -0,0 +1,76 @@ +package diagnostic + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c DiagnosticClient) Delete(ctx context.Context, id DiagnosticId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/method_get.go b/resource-manager/apimanagement/2024-05-01/diagnostic/method_get.go new file mode 100644 index 00000000000..af2a7f7943a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/method_get.go @@ -0,0 +1,54 @@ +package diagnostic + +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 *DiagnosticContract +} + +// Get ... +func (c DiagnosticClient) Get(ctx context.Context, id DiagnosticId) (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 DiagnosticContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/diagnostic/method_getentitytag.go new file mode 100644 index 00000000000..8be53cb6cbf --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/method_getentitytag.go @@ -0,0 +1,46 @@ +package diagnostic + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c DiagnosticClient) GetEntityTag(ctx context.Context, id DiagnosticId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/diagnostic/method_listbyservice.go new file mode 100644 index 00000000000..8f84fb8b874 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/method_listbyservice.go @@ -0,0 +1,141 @@ +package diagnostic + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DiagnosticContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []DiagnosticContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c DiagnosticClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/diagnostics", 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 *[]DiagnosticContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c DiagnosticClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, DiagnosticContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DiagnosticClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate DiagnosticContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]DiagnosticContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/method_update.go b/resource-manager/apimanagement/2024-05-01/diagnostic/method_update.go new file mode 100644 index 00000000000..a98dfa6617c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/method_update.go @@ -0,0 +1,87 @@ +package diagnostic + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DiagnosticContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c DiagnosticClient) Update(ctx context.Context, id DiagnosticId, input DiagnosticContract, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 DiagnosticContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/method_workspacediagnosticcreateorupdate.go b/resource-manager/apimanagement/2024-05-01/diagnostic/method_workspacediagnosticcreateorupdate.go new file mode 100644 index 00000000000..4660270804a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/method_workspacediagnosticcreateorupdate.go @@ -0,0 +1,88 @@ +package diagnostic + +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 WorkspaceDiagnosticCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DiagnosticContract +} + +type WorkspaceDiagnosticCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceDiagnosticCreateOrUpdateOperationOptions() WorkspaceDiagnosticCreateOrUpdateOperationOptions { + return WorkspaceDiagnosticCreateOrUpdateOperationOptions{} +} + +func (o WorkspaceDiagnosticCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceDiagnosticCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceDiagnosticCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceDiagnosticCreateOrUpdate ... +func (c DiagnosticClient) WorkspaceDiagnosticCreateOrUpdate(ctx context.Context, id WorkspaceDiagnosticId, input DiagnosticContract, options WorkspaceDiagnosticCreateOrUpdateOperationOptions) (result WorkspaceDiagnosticCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 DiagnosticContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/method_workspacediagnosticdelete.go b/resource-manager/apimanagement/2024-05-01/diagnostic/method_workspacediagnosticdelete.go new file mode 100644 index 00000000000..f980ab6458e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/method_workspacediagnosticdelete.go @@ -0,0 +1,76 @@ +package diagnostic + +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 WorkspaceDiagnosticDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type WorkspaceDiagnosticDeleteOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceDiagnosticDeleteOperationOptions() WorkspaceDiagnosticDeleteOperationOptions { + return WorkspaceDiagnosticDeleteOperationOptions{} +} + +func (o WorkspaceDiagnosticDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceDiagnosticDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceDiagnosticDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceDiagnosticDelete ... +func (c DiagnosticClient) WorkspaceDiagnosticDelete(ctx context.Context, id WorkspaceDiagnosticId, options WorkspaceDiagnosticDeleteOperationOptions) (result WorkspaceDiagnosticDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/method_workspacediagnosticget.go b/resource-manager/apimanagement/2024-05-01/diagnostic/method_workspacediagnosticget.go new file mode 100644 index 00000000000..5145c6c8a81 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/method_workspacediagnosticget.go @@ -0,0 +1,54 @@ +package diagnostic + +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 WorkspaceDiagnosticGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DiagnosticContract +} + +// WorkspaceDiagnosticGet ... +func (c DiagnosticClient) WorkspaceDiagnosticGet(ctx context.Context, id WorkspaceDiagnosticId) (result WorkspaceDiagnosticGetOperationResponse, 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 DiagnosticContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/method_workspacediagnosticgetentitytag.go b/resource-manager/apimanagement/2024-05-01/diagnostic/method_workspacediagnosticgetentitytag.go new file mode 100644 index 00000000000..11e39aaa66c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/method_workspacediagnosticgetentitytag.go @@ -0,0 +1,46 @@ +package diagnostic + +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 WorkspaceDiagnosticGetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceDiagnosticGetEntityTag ... +func (c DiagnosticClient) WorkspaceDiagnosticGetEntityTag(ctx context.Context, id WorkspaceDiagnosticId) (result WorkspaceDiagnosticGetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/method_workspacediagnosticlistbyworkspace.go b/resource-manager/apimanagement/2024-05-01/diagnostic/method_workspacediagnosticlistbyworkspace.go new file mode 100644 index 00000000000..6293c663996 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/method_workspacediagnosticlistbyworkspace.go @@ -0,0 +1,141 @@ +package diagnostic + +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 WorkspaceDiagnosticListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DiagnosticContract +} + +type WorkspaceDiagnosticListByWorkspaceCompleteResult struct { + LatestHttpResponse *http.Response + Items []DiagnosticContract +} + +type WorkspaceDiagnosticListByWorkspaceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultWorkspaceDiagnosticListByWorkspaceOperationOptions() WorkspaceDiagnosticListByWorkspaceOperationOptions { + return WorkspaceDiagnosticListByWorkspaceOperationOptions{} +} + +func (o WorkspaceDiagnosticListByWorkspaceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceDiagnosticListByWorkspaceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceDiagnosticListByWorkspaceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspaceDiagnosticListByWorkspaceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceDiagnosticListByWorkspaceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceDiagnosticListByWorkspace ... +func (c DiagnosticClient) WorkspaceDiagnosticListByWorkspace(ctx context.Context, id WorkspaceId, options WorkspaceDiagnosticListByWorkspaceOperationOptions) (result WorkspaceDiagnosticListByWorkspaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspaceDiagnosticListByWorkspaceCustomPager{}, + Path: fmt.Sprintf("%s/diagnostics", 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 *[]DiagnosticContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceDiagnosticListByWorkspaceComplete retrieves all the results into a single object +func (c DiagnosticClient) WorkspaceDiagnosticListByWorkspaceComplete(ctx context.Context, id WorkspaceId, options WorkspaceDiagnosticListByWorkspaceOperationOptions) (WorkspaceDiagnosticListByWorkspaceCompleteResult, error) { + return c.WorkspaceDiagnosticListByWorkspaceCompleteMatchingPredicate(ctx, id, options, DiagnosticContractOperationPredicate{}) +} + +// WorkspaceDiagnosticListByWorkspaceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DiagnosticClient) WorkspaceDiagnosticListByWorkspaceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options WorkspaceDiagnosticListByWorkspaceOperationOptions, predicate DiagnosticContractOperationPredicate) (result WorkspaceDiagnosticListByWorkspaceCompleteResult, err error) { + items := make([]DiagnosticContract, 0) + + resp, err := c.WorkspaceDiagnosticListByWorkspace(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceDiagnosticListByWorkspaceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/method_workspacediagnosticupdate.go b/resource-manager/apimanagement/2024-05-01/diagnostic/method_workspacediagnosticupdate.go new file mode 100644 index 00000000000..ff1f4a0a25b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/method_workspacediagnosticupdate.go @@ -0,0 +1,87 @@ +package diagnostic + +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 WorkspaceDiagnosticUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DiagnosticContract +} + +type WorkspaceDiagnosticUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceDiagnosticUpdateOperationOptions() WorkspaceDiagnosticUpdateOperationOptions { + return WorkspaceDiagnosticUpdateOperationOptions{} +} + +func (o WorkspaceDiagnosticUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceDiagnosticUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceDiagnosticUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceDiagnosticUpdate ... +func (c DiagnosticClient) WorkspaceDiagnosticUpdate(ctx context.Context, id WorkspaceDiagnosticId, input DiagnosticUpdateContract, options WorkspaceDiagnosticUpdateOperationOptions) (result WorkspaceDiagnosticUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 DiagnosticContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/model_bodydiagnosticsettings.go b/resource-manager/apimanagement/2024-05-01/diagnostic/model_bodydiagnosticsettings.go new file mode 100644 index 00000000000..5c1e7e81154 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/model_bodydiagnosticsettings.go @@ -0,0 +1,8 @@ +package diagnostic + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BodyDiagnosticSettings struct { + Bytes *int64 `json:"bytes,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/model_datamasking.go b/resource-manager/apimanagement/2024-05-01/diagnostic/model_datamasking.go new file mode 100644 index 00000000000..2e76abd5c6b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/model_datamasking.go @@ -0,0 +1,9 @@ +package diagnostic + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataMasking struct { + Headers *[]DataMaskingEntity `json:"headers,omitempty"` + QueryParams *[]DataMaskingEntity `json:"queryParams,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/model_datamaskingentity.go b/resource-manager/apimanagement/2024-05-01/diagnostic/model_datamaskingentity.go new file mode 100644 index 00000000000..2b733980670 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/model_datamaskingentity.go @@ -0,0 +1,9 @@ +package diagnostic + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataMaskingEntity struct { + Mode *DataMaskingMode `json:"mode,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/model_diagnosticcontract.go b/resource-manager/apimanagement/2024-05-01/diagnostic/model_diagnosticcontract.go new file mode 100644 index 00000000000..879a408c4cf --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/model_diagnosticcontract.go @@ -0,0 +1,11 @@ +package diagnostic + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DiagnosticContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/model_diagnosticcontractproperties.go b/resource-manager/apimanagement/2024-05-01/diagnostic/model_diagnosticcontractproperties.go new file mode 100644 index 00000000000..402793421a3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/model_diagnosticcontractproperties.go @@ -0,0 +1,17 @@ +package diagnostic + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticContractProperties struct { + AlwaysLog *AlwaysLog `json:"alwaysLog,omitempty"` + Backend *PipelineDiagnosticSettings `json:"backend,omitempty"` + Frontend *PipelineDiagnosticSettings `json:"frontend,omitempty"` + HTTPCorrelationProtocol *HTTPCorrelationProtocol `json:"httpCorrelationProtocol,omitempty"` + LogClientIP *bool `json:"logClientIp,omitempty"` + LoggerId string `json:"loggerId"` + Metrics *bool `json:"metrics,omitempty"` + OperationNameFormat *OperationNameFormat `json:"operationNameFormat,omitempty"` + Sampling *SamplingSettings `json:"sampling,omitempty"` + Verbosity *Verbosity `json:"verbosity,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/model_diagnosticcontractupdateproperties.go b/resource-manager/apimanagement/2024-05-01/diagnostic/model_diagnosticcontractupdateproperties.go new file mode 100644 index 00000000000..debae2a8af0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/model_diagnosticcontractupdateproperties.go @@ -0,0 +1,17 @@ +package diagnostic + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticContractUpdateProperties struct { + AlwaysLog *AlwaysLog `json:"alwaysLog,omitempty"` + Backend *PipelineDiagnosticSettings `json:"backend,omitempty"` + Frontend *PipelineDiagnosticSettings `json:"frontend,omitempty"` + HTTPCorrelationProtocol *HTTPCorrelationProtocol `json:"httpCorrelationProtocol,omitempty"` + LogClientIP *bool `json:"logClientIp,omitempty"` + LoggerId *string `json:"loggerId,omitempty"` + Metrics *bool `json:"metrics,omitempty"` + OperationNameFormat *OperationNameFormat `json:"operationNameFormat,omitempty"` + Sampling *SamplingSettings `json:"sampling,omitempty"` + Verbosity *Verbosity `json:"verbosity,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/model_diagnosticupdatecontract.go b/resource-manager/apimanagement/2024-05-01/diagnostic/model_diagnosticupdatecontract.go new file mode 100644 index 00000000000..615cafe20f0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/model_diagnosticupdatecontract.go @@ -0,0 +1,11 @@ +package diagnostic + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticUpdateContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DiagnosticContractUpdateProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/model_httpmessagediagnostic.go b/resource-manager/apimanagement/2024-05-01/diagnostic/model_httpmessagediagnostic.go new file mode 100644 index 00000000000..f37eb16b51c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/model_httpmessagediagnostic.go @@ -0,0 +1,10 @@ +package diagnostic + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HTTPMessageDiagnostic struct { + Body *BodyDiagnosticSettings `json:"body,omitempty"` + DataMasking *DataMasking `json:"dataMasking,omitempty"` + Headers *[]string `json:"headers,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/model_pipelinediagnosticsettings.go b/resource-manager/apimanagement/2024-05-01/diagnostic/model_pipelinediagnosticsettings.go new file mode 100644 index 00000000000..329404c1999 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/model_pipelinediagnosticsettings.go @@ -0,0 +1,9 @@ +package diagnostic + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PipelineDiagnosticSettings struct { + Request *HTTPMessageDiagnostic `json:"request,omitempty"` + Response *HTTPMessageDiagnostic `json:"response,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/model_samplingsettings.go b/resource-manager/apimanagement/2024-05-01/diagnostic/model_samplingsettings.go new file mode 100644 index 00000000000..b4efe2c80ea --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/model_samplingsettings.go @@ -0,0 +1,9 @@ +package diagnostic + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SamplingSettings struct { + Percentage *float64 `json:"percentage,omitempty"` + SamplingType *SamplingType `json:"samplingType,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/diagnostic/predicates.go b/resource-manager/apimanagement/2024-05-01/diagnostic/predicates.go new file mode 100644 index 00000000000..1a3641637d2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/predicates.go @@ -0,0 +1,27 @@ +package diagnostic + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DiagnosticContractOperationPredicate) Matches(input DiagnosticContract) 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/apimanagement/2024-05-01/diagnostic/version.go b/resource-manager/apimanagement/2024-05-01/diagnostic/version.go new file mode 100644 index 00000000000..c1ab5e6ace2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/diagnostic/version.go @@ -0,0 +1,12 @@ +package diagnostic + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/diagnostic/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/documentationresource/README.md b/resource-manager/apimanagement/2024-05-01/documentationresource/README.md new file mode 100644 index 00000000000..4990c189960 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/documentationresource/README.md @@ -0,0 +1,127 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/documentationresource` Documentation + +The `documentationresource` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/documentationresource" +``` + + +### Client Initialization + +```go +client := documentationresource.NewDocumentationResourceClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DocumentationResourceClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := documentationresource.NewDocumentationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "documentationIdValue") + +payload := documentationresource.DocumentationContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, documentationresource.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DocumentationResourceClient.Delete` + +```go +ctx := context.TODO() +id := documentationresource.NewDocumentationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "documentationIdValue") + +read, err := client.Delete(ctx, id, documentationresource.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DocumentationResourceClient.Get` + +```go +ctx := context.TODO() +id := documentationresource.NewDocumentationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "documentationIdValue") + +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: `DocumentationResourceClient.GetEntityTag` + +```go +ctx := context.TODO() +id := documentationresource.NewDocumentationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "documentationIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DocumentationResourceClient.ListByService` + +```go +ctx := context.TODO() +id := documentationresource.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, documentationresource.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, documentationresource.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DocumentationResourceClient.Update` + +```go +ctx := context.TODO() +id := documentationresource.NewDocumentationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "documentationIdValue") + +payload := documentationresource.DocumentationUpdateContract{ + // ... +} + + +read, err := client.Update(ctx, id, payload, documentationresource.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/documentationresource/client.go b/resource-manager/apimanagement/2024-05-01/documentationresource/client.go new file mode 100644 index 00000000000..84d6809b879 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/documentationresource/client.go @@ -0,0 +1,26 @@ +package documentationresource + +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 DocumentationResourceClient struct { + Client *resourcemanager.Client +} + +func NewDocumentationResourceClientWithBaseURI(sdkApi sdkEnv.Api) (*DocumentationResourceClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "documentationresource", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DocumentationResourceClient: %+v", err) + } + + return &DocumentationResourceClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/documentationresource/id_documentation.go b/resource-manager/apimanagement/2024-05-01/documentationresource/id_documentation.go new file mode 100644 index 00000000000..6841fc7c512 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/documentationresource/id_documentation.go @@ -0,0 +1,139 @@ +package documentationresource + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DocumentationId{}) +} + +var _ resourceids.ResourceId = &DocumentationId{} + +// DocumentationId is a struct representing the Resource ID for a Documentation +type DocumentationId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + DocumentationId string +} + +// NewDocumentationID returns a new DocumentationId struct +func NewDocumentationID(subscriptionId string, resourceGroupName string, serviceName string, documentationId string) DocumentationId { + return DocumentationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + DocumentationId: documentationId, + } +} + +// ParseDocumentationID parses 'input' into a DocumentationId +func ParseDocumentationID(input string) (*DocumentationId, error) { + parser := resourceids.NewParserFromResourceIdType(&DocumentationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DocumentationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDocumentationIDInsensitively parses 'input' case-insensitively into a DocumentationId +// note: this method should only be used for API response data and not user input +func ParseDocumentationIDInsensitively(input string) (*DocumentationId, error) { + parser := resourceids.NewParserFromResourceIdType(&DocumentationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DocumentationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DocumentationId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.DocumentationId, ok = input.Parsed["documentationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "documentationId", input) + } + + return nil +} + +// ValidateDocumentationID checks that 'input' can be parsed as a Documentation ID +func ValidateDocumentationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseDocumentationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Documentation ID +func (id DocumentationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/documentations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.DocumentationId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Documentation ID +func (id DocumentationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticDocumentations", "documentations", "documentations"), + resourceids.UserSpecifiedSegment("documentationId", "documentationIdValue"), + } +} + +// String returns a human-readable description of this Documentation ID +func (id DocumentationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Documentation: %q", id.DocumentationId), + } + return fmt.Sprintf("Documentation (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/documentationresource/id_documentation_test.go b/resource-manager/apimanagement/2024-05-01/documentationresource/id_documentation_test.go new file mode 100644 index 00000000000..8ee3420bae4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/documentationresource/id_documentation_test.go @@ -0,0 +1,327 @@ +package documentationresource + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &DocumentationId{} + +func TestNewDocumentationID(t *testing.T) { + id := NewDocumentationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "documentationIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.DocumentationId != "documentationIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'DocumentationId'", id.DocumentationId, "documentationIdValue") + } +} + +func TestFormatDocumentationID(t *testing.T) { + actual := NewDocumentationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "documentationIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/documentations/documentationIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDocumentationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DocumentationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/documentations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/documentations/documentationIdValue", + Expected: &DocumentationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + DocumentationId: "documentationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/documentations/documentationIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDocumentationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.DocumentationId != v.Expected.DocumentationId { + t.Fatalf("Expected %q but got %q for DocumentationId", v.Expected.DocumentationId, actual.DocumentationId) + } + + } +} + +func TestParseDocumentationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DocumentationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/documentations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/dOcUmEnTaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/documentations/documentationIdValue", + Expected: &DocumentationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + DocumentationId: "documentationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/documentations/documentationIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/dOcUmEnTaTiOnS/dOcUmEnTaTiOnIdVaLuE", + Expected: &DocumentationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + DocumentationId: "dOcUmEnTaTiOnIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/dOcUmEnTaTiOnS/dOcUmEnTaTiOnIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDocumentationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.DocumentationId != v.Expected.DocumentationId { + t.Fatalf("Expected %q but got %q for DocumentationId", v.Expected.DocumentationId, actual.DocumentationId) + } + + } +} + +func TestSegmentsForDocumentationId(t *testing.T) { + segments := DocumentationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DocumentationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/documentationresource/id_service.go b/resource-manager/apimanagement/2024-05-01/documentationresource/id_service.go new file mode 100644 index 00000000000..a25669a238f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/documentationresource/id_service.go @@ -0,0 +1,130 @@ +package documentationresource + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/documentationresource/id_service_test.go b/resource-manager/apimanagement/2024-05-01/documentationresource/id_service_test.go new file mode 100644 index 00000000000..cdd775a7d94 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/documentationresource/id_service_test.go @@ -0,0 +1,282 @@ +package documentationresource + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/documentationresource/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/documentationresource/method_createorupdate.go new file mode 100644 index 00000000000..dba91b12734 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/documentationresource/method_createorupdate.go @@ -0,0 +1,88 @@ +package documentationresource + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DocumentationContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c DocumentationResourceClient) CreateOrUpdate(ctx context.Context, id DocumentationId, input DocumentationContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 DocumentationContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/documentationresource/method_delete.go b/resource-manager/apimanagement/2024-05-01/documentationresource/method_delete.go new file mode 100644 index 00000000000..dc215c80397 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/documentationresource/method_delete.go @@ -0,0 +1,76 @@ +package documentationresource + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c DocumentationResourceClient) Delete(ctx context.Context, id DocumentationId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/documentationresource/method_get.go b/resource-manager/apimanagement/2024-05-01/documentationresource/method_get.go new file mode 100644 index 00000000000..db62fe89422 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/documentationresource/method_get.go @@ -0,0 +1,54 @@ +package documentationresource + +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 *DocumentationContract +} + +// Get ... +func (c DocumentationResourceClient) Get(ctx context.Context, id DocumentationId) (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 DocumentationContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/documentationresource/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/documentationresource/method_getentitytag.go new file mode 100644 index 00000000000..2a462006188 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/documentationresource/method_getentitytag.go @@ -0,0 +1,46 @@ +package documentationresource + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c DocumentationResourceClient) GetEntityTag(ctx context.Context, id DocumentationId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/documentationresource/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/documentationresource/method_listbyservice.go new file mode 100644 index 00000000000..fd2023ee4d1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/documentationresource/method_listbyservice.go @@ -0,0 +1,141 @@ +package documentationresource + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DocumentationContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []DocumentationContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c DocumentationResourceClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/documentations", 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 *[]DocumentationContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c DocumentationResourceClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, DocumentationContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DocumentationResourceClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate DocumentationContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]DocumentationContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/documentationresource/method_update.go b/resource-manager/apimanagement/2024-05-01/documentationresource/method_update.go new file mode 100644 index 00000000000..74fdf96af9a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/documentationresource/method_update.go @@ -0,0 +1,87 @@ +package documentationresource + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DocumentationContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c DocumentationResourceClient) Update(ctx context.Context, id DocumentationId, input DocumentationUpdateContract, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 DocumentationContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/documentationresource/model_documentationcontract.go b/resource-manager/apimanagement/2024-05-01/documentationresource/model_documentationcontract.go new file mode 100644 index 00000000000..c52ac2cf045 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/documentationresource/model_documentationcontract.go @@ -0,0 +1,11 @@ +package documentationresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DocumentationContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DocumentationContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/documentationresource/model_documentationcontractproperties.go b/resource-manager/apimanagement/2024-05-01/documentationresource/model_documentationcontractproperties.go new file mode 100644 index 00000000000..3cbdd397b4a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/documentationresource/model_documentationcontractproperties.go @@ -0,0 +1,9 @@ +package documentationresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DocumentationContractProperties struct { + Content *string `json:"content,omitempty"` + Title *string `json:"title,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/documentationresource/model_documentationupdatecontract.go b/resource-manager/apimanagement/2024-05-01/documentationresource/model_documentationupdatecontract.go new file mode 100644 index 00000000000..f1b77cd17d6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/documentationresource/model_documentationupdatecontract.go @@ -0,0 +1,8 @@ +package documentationresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DocumentationUpdateContract struct { + Properties *DocumentationContractProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/documentationresource/predicates.go b/resource-manager/apimanagement/2024-05-01/documentationresource/predicates.go new file mode 100644 index 00000000000..5c6853fdaa4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/documentationresource/predicates.go @@ -0,0 +1,27 @@ +package documentationresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DocumentationContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DocumentationContractOperationPredicate) Matches(input DocumentationContract) 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/apimanagement/2024-05-01/documentationresource/version.go b/resource-manager/apimanagement/2024-05-01/documentationresource/version.go new file mode 100644 index 00000000000..afee214c676 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/documentationresource/version.go @@ -0,0 +1,12 @@ +package documentationresource + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/documentationresource/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplate/README.md b/resource-manager/apimanagement/2024-05-01/emailtemplate/README.md new file mode 100644 index 00000000000..627b9152d33 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplate/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/emailtemplate` Documentation + +The `emailtemplate` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/emailtemplate" +``` + + +### Client Initialization + +```go +client := emailtemplate.NewEmailTemplateClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `EmailTemplateClient.ListByService` + +```go +ctx := context.TODO() +id := emailtemplate.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, emailtemplate.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, emailtemplate.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplate/client.go b/resource-manager/apimanagement/2024-05-01/emailtemplate/client.go new file mode 100644 index 00000000000..019165ffa63 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplate/client.go @@ -0,0 +1,26 @@ +package emailtemplate + +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 EmailTemplateClient struct { + Client *resourcemanager.Client +} + +func NewEmailTemplateClientWithBaseURI(sdkApi sdkEnv.Api) (*EmailTemplateClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "emailtemplate", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EmailTemplateClient: %+v", err) + } + + return &EmailTemplateClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplate/id_service.go b/resource-manager/apimanagement/2024-05-01/emailtemplate/id_service.go new file mode 100644 index 00000000000..ad519c3023d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplate/id_service.go @@ -0,0 +1,130 @@ +package emailtemplate + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplate/id_service_test.go b/resource-manager/apimanagement/2024-05-01/emailtemplate/id_service_test.go new file mode 100644 index 00000000000..61cbed3860d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplate/id_service_test.go @@ -0,0 +1,282 @@ +package emailtemplate + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplate/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/emailtemplate/method_listbyservice.go new file mode 100644 index 00000000000..c18ee603b17 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplate/method_listbyservice.go @@ -0,0 +1,141 @@ +package emailtemplate + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EmailTemplateContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []EmailTemplateContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c EmailTemplateClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/templates", 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 *[]EmailTemplateContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c EmailTemplateClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, EmailTemplateContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EmailTemplateClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate EmailTemplateContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]EmailTemplateContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplate/model_emailtemplatecontract.go b/resource-manager/apimanagement/2024-05-01/emailtemplate/model_emailtemplatecontract.go new file mode 100644 index 00000000000..29ab68c1a42 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplate/model_emailtemplatecontract.go @@ -0,0 +1,11 @@ +package emailtemplate + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EmailTemplateContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *EmailTemplateContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplate/model_emailtemplatecontractproperties.go b/resource-manager/apimanagement/2024-05-01/emailtemplate/model_emailtemplatecontractproperties.go new file mode 100644 index 00000000000..0fd8e5f7aa5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplate/model_emailtemplatecontractproperties.go @@ -0,0 +1,13 @@ +package emailtemplate + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EmailTemplateContractProperties struct { + Body string `json:"body"` + Description *string `json:"description,omitempty"` + IsDefault *bool `json:"isDefault,omitempty"` + Parameters *[]EmailTemplateParametersContractProperties `json:"parameters,omitempty"` + Subject string `json:"subject"` + Title *string `json:"title,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplate/model_emailtemplateparameterscontractproperties.go b/resource-manager/apimanagement/2024-05-01/emailtemplate/model_emailtemplateparameterscontractproperties.go new file mode 100644 index 00000000000..b798fba72dc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplate/model_emailtemplateparameterscontractproperties.go @@ -0,0 +1,10 @@ +package emailtemplate + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EmailTemplateParametersContractProperties struct { + Description *string `json:"description,omitempty"` + Name *string `json:"name,omitempty"` + Title *string `json:"title,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplate/predicates.go b/resource-manager/apimanagement/2024-05-01/emailtemplate/predicates.go new file mode 100644 index 00000000000..9a8a270e788 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplate/predicates.go @@ -0,0 +1,27 @@ +package emailtemplate + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EmailTemplateContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p EmailTemplateContractOperationPredicate) Matches(input EmailTemplateContract) 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/apimanagement/2024-05-01/emailtemplate/version.go b/resource-manager/apimanagement/2024-05-01/emailtemplate/version.go new file mode 100644 index 00000000000..5059d2857cb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplate/version.go @@ -0,0 +1,12 @@ +package emailtemplate + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/emailtemplate/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplates/README.md b/resource-manager/apimanagement/2024-05-01/emailtemplates/README.md new file mode 100644 index 00000000000..edada916ce9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplates/README.md @@ -0,0 +1,110 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/emailtemplates` Documentation + +The `emailtemplates` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/emailtemplates" +``` + + +### Client Initialization + +```go +client := emailtemplates.NewEmailTemplatesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `EmailTemplatesClient.EmailTemplateCreateOrUpdate` + +```go +ctx := context.TODO() +id := emailtemplates.NewTemplateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "accountClosedDeveloper") + +payload := emailtemplates.EmailTemplateUpdateParameters{ + // ... +} + + +read, err := client.EmailTemplateCreateOrUpdate(ctx, id, payload, emailtemplates.DefaultEmailTemplateCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EmailTemplatesClient.EmailTemplateDelete` + +```go +ctx := context.TODO() +id := emailtemplates.NewTemplateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "accountClosedDeveloper") + +read, err := client.EmailTemplateDelete(ctx, id, emailtemplates.DefaultEmailTemplateDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EmailTemplatesClient.EmailTemplateGet` + +```go +ctx := context.TODO() +id := emailtemplates.NewTemplateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "accountClosedDeveloper") + +read, err := client.EmailTemplateGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EmailTemplatesClient.EmailTemplateGetEntityTag` + +```go +ctx := context.TODO() +id := emailtemplates.NewTemplateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "accountClosedDeveloper") + +read, err := client.EmailTemplateGetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EmailTemplatesClient.EmailTemplateUpdate` + +```go +ctx := context.TODO() +id := emailtemplates.NewTemplateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "accountClosedDeveloper") + +payload := emailtemplates.EmailTemplateUpdateParameters{ + // ... +} + + +read, err := client.EmailTemplateUpdate(ctx, id, payload, emailtemplates.DefaultEmailTemplateUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplates/client.go b/resource-manager/apimanagement/2024-05-01/emailtemplates/client.go new file mode 100644 index 00000000000..9f3bc8ed59b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplates/client.go @@ -0,0 +1,26 @@ +package emailtemplates + +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 EmailTemplatesClient struct { + Client *resourcemanager.Client +} + +func NewEmailTemplatesClientWithBaseURI(sdkApi sdkEnv.Api) (*EmailTemplatesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "emailtemplates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EmailTemplatesClient: %+v", err) + } + + return &EmailTemplatesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplates/constants.go b/resource-manager/apimanagement/2024-05-01/emailtemplates/constants.go new file mode 100644 index 00000000000..19dadfefea4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplates/constants.go @@ -0,0 +1,87 @@ +package emailtemplates + +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 TemplateName string + +const ( + TemplateNameAccountClosedDeveloper TemplateName = "accountClosedDeveloper" + TemplateNameApplicationApprovedNotificationMessage TemplateName = "applicationApprovedNotificationMessage" + TemplateNameConfirmSignUpIdentityDefault TemplateName = "confirmSignUpIdentityDefault" + TemplateNameEmailChangeIdentityDefault TemplateName = "emailChangeIdentityDefault" + TemplateNameInviteUserNotificationMessage TemplateName = "inviteUserNotificationMessage" + TemplateNameNewCommentNotificationMessage TemplateName = "newCommentNotificationMessage" + TemplateNameNewDeveloperNotificationMessage TemplateName = "newDeveloperNotificationMessage" + TemplateNameNewIssueNotificationMessage TemplateName = "newIssueNotificationMessage" + TemplateNamePasswordResetByAdminNotificationMessage TemplateName = "passwordResetByAdminNotificationMessage" + TemplateNamePasswordResetIdentityDefault TemplateName = "passwordResetIdentityDefault" + TemplateNamePurchaseDeveloperNotificationMessage TemplateName = "purchaseDeveloperNotificationMessage" + TemplateNameQuotaLimitApproachingDeveloperNotificationMessage TemplateName = "quotaLimitApproachingDeveloperNotificationMessage" + TemplateNameRejectDeveloperNotificationMessage TemplateName = "rejectDeveloperNotificationMessage" + TemplateNameRequestDeveloperNotificationMessage TemplateName = "requestDeveloperNotificationMessage" +) + +func PossibleValuesForTemplateName() []string { + return []string{ + string(TemplateNameAccountClosedDeveloper), + string(TemplateNameApplicationApprovedNotificationMessage), + string(TemplateNameConfirmSignUpIdentityDefault), + string(TemplateNameEmailChangeIdentityDefault), + string(TemplateNameInviteUserNotificationMessage), + string(TemplateNameNewCommentNotificationMessage), + string(TemplateNameNewDeveloperNotificationMessage), + string(TemplateNameNewIssueNotificationMessage), + string(TemplateNamePasswordResetByAdminNotificationMessage), + string(TemplateNamePasswordResetIdentityDefault), + string(TemplateNamePurchaseDeveloperNotificationMessage), + string(TemplateNameQuotaLimitApproachingDeveloperNotificationMessage), + string(TemplateNameRejectDeveloperNotificationMessage), + string(TemplateNameRequestDeveloperNotificationMessage), + } +} + +func (s *TemplateName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTemplateName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTemplateName(input string) (*TemplateName, error) { + vals := map[string]TemplateName{ + "accountcloseddeveloper": TemplateNameAccountClosedDeveloper, + "applicationapprovednotificationmessage": TemplateNameApplicationApprovedNotificationMessage, + "confirmsignupidentitydefault": TemplateNameConfirmSignUpIdentityDefault, + "emailchangeidentitydefault": TemplateNameEmailChangeIdentityDefault, + "inviteusernotificationmessage": TemplateNameInviteUserNotificationMessage, + "newcommentnotificationmessage": TemplateNameNewCommentNotificationMessage, + "newdevelopernotificationmessage": TemplateNameNewDeveloperNotificationMessage, + "newissuenotificationmessage": TemplateNameNewIssueNotificationMessage, + "passwordresetbyadminnotificationmessage": TemplateNamePasswordResetByAdminNotificationMessage, + "passwordresetidentitydefault": TemplateNamePasswordResetIdentityDefault, + "purchasedevelopernotificationmessage": TemplateNamePurchaseDeveloperNotificationMessage, + "quotalimitapproachingdevelopernotificationmessage": TemplateNameQuotaLimitApproachingDeveloperNotificationMessage, + "rejectdevelopernotificationmessage": TemplateNameRejectDeveloperNotificationMessage, + "requestdevelopernotificationmessage": TemplateNameRequestDeveloperNotificationMessage, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TemplateName(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplates/id_template.go b/resource-manager/apimanagement/2024-05-01/emailtemplates/id_template.go new file mode 100644 index 00000000000..b10f4a91dd1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplates/id_template.go @@ -0,0 +1,147 @@ +package emailtemplates + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TemplateId{}) +} + +var _ resourceids.ResourceId = &TemplateId{} + +// TemplateId is a struct representing the Resource ID for a Template +type TemplateId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + TemplateName TemplateName +} + +// NewTemplateID returns a new TemplateId struct +func NewTemplateID(subscriptionId string, resourceGroupName string, serviceName string, templateName TemplateName) TemplateId { + return TemplateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + TemplateName: templateName, + } +} + +// ParseTemplateID parses 'input' into a TemplateId +func ParseTemplateID(input string) (*TemplateId, error) { + parser := resourceids.NewParserFromResourceIdType(&TemplateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TemplateId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTemplateIDInsensitively parses 'input' case-insensitively into a TemplateId +// note: this method should only be used for API response data and not user input +func ParseTemplateIDInsensitively(input string) (*TemplateId, error) { + parser := resourceids.NewParserFromResourceIdType(&TemplateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TemplateId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TemplateId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if v, ok := input.Parsed["templateName"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "templateName", input) + } + + templateName, err := parseTemplateName(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.TemplateName = *templateName + } + + return nil +} + +// ValidateTemplateID checks that 'input' can be parsed as a Template ID +func ValidateTemplateID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseTemplateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Template ID +func (id TemplateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/templates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, string(id.TemplateName)) +} + +// Segments returns a slice of Resource ID Segments which comprise this Template ID +func (id TemplateId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticTemplates", "templates", "templates"), + resourceids.ConstantSegment("templateName", PossibleValuesForTemplateName(), "accountClosedDeveloper"), + } +} + +// String returns a human-readable description of this Template ID +func (id TemplateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Template Name: %q", string(id.TemplateName)), + } + return fmt.Sprintf("Template (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplates/id_template_test.go b/resource-manager/apimanagement/2024-05-01/emailtemplates/id_template_test.go new file mode 100644 index 00000000000..51377891505 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplates/id_template_test.go @@ -0,0 +1,327 @@ +package emailtemplates + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TemplateId{} + +func TestNewTemplateID(t *testing.T) { + id := NewTemplateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "accountClosedDeveloper") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.TemplateName != "accountClosedDeveloper" { + t.Fatalf("Expected %q but got %q for Segment 'TemplateName'", id.TemplateName, "accountClosedDeveloper") + } +} + +func TestFormatTemplateID(t *testing.T) { + actual := NewTemplateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "accountClosedDeveloper").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/templates/accountClosedDeveloper" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTemplateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TemplateId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/templates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/templates/accountClosedDeveloper", + Expected: &TemplateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + TemplateName: "accountClosedDeveloper", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/templates/accountClosedDeveloper/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTemplateID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.TemplateName != v.Expected.TemplateName { + t.Fatalf("Expected %q but got %q for TemplateName", v.Expected.TemplateName, actual.TemplateName) + } + + } +} + +func TestParseTemplateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TemplateId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/templates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tEmPlAtEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/templates/accountClosedDeveloper", + Expected: &TemplateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + TemplateName: "accountClosedDeveloper", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/templates/accountClosedDeveloper/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tEmPlAtEs/aCcOuNtClOsEdDeVeLoPeR", + Expected: &TemplateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + TemplateName: "accountClosedDeveloper", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tEmPlAtEs/aCcOuNtClOsEdDeVeLoPeR/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTemplateIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.TemplateName != v.Expected.TemplateName { + t.Fatalf("Expected %q but got %q for TemplateName", v.Expected.TemplateName, actual.TemplateName) + } + + } +} + +func TestSegmentsForTemplateId(t *testing.T) { + segments := TemplateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TemplateId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplates/method_emailtemplatecreateorupdate.go b/resource-manager/apimanagement/2024-05-01/emailtemplates/method_emailtemplatecreateorupdate.go new file mode 100644 index 00000000000..8f48b83acfd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplates/method_emailtemplatecreateorupdate.go @@ -0,0 +1,88 @@ +package emailtemplates + +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 EmailTemplateCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EmailTemplateContract +} + +type EmailTemplateCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultEmailTemplateCreateOrUpdateOperationOptions() EmailTemplateCreateOrUpdateOperationOptions { + return EmailTemplateCreateOrUpdateOperationOptions{} +} + +func (o EmailTemplateCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o EmailTemplateCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o EmailTemplateCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// EmailTemplateCreateOrUpdate ... +func (c EmailTemplatesClient) EmailTemplateCreateOrUpdate(ctx context.Context, id TemplateId, input EmailTemplateUpdateParameters, options EmailTemplateCreateOrUpdateOperationOptions) (result EmailTemplateCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 EmailTemplateContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplates/method_emailtemplatedelete.go b/resource-manager/apimanagement/2024-05-01/emailtemplates/method_emailtemplatedelete.go new file mode 100644 index 00000000000..3bea1260006 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplates/method_emailtemplatedelete.go @@ -0,0 +1,76 @@ +package emailtemplates + +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 EmailTemplateDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type EmailTemplateDeleteOperationOptions struct { + IfMatch *string +} + +func DefaultEmailTemplateDeleteOperationOptions() EmailTemplateDeleteOperationOptions { + return EmailTemplateDeleteOperationOptions{} +} + +func (o EmailTemplateDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o EmailTemplateDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o EmailTemplateDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// EmailTemplateDelete ... +func (c EmailTemplatesClient) EmailTemplateDelete(ctx context.Context, id TemplateId, options EmailTemplateDeleteOperationOptions) (result EmailTemplateDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplates/method_emailtemplateget.go b/resource-manager/apimanagement/2024-05-01/emailtemplates/method_emailtemplateget.go new file mode 100644 index 00000000000..b9686668bf3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplates/method_emailtemplateget.go @@ -0,0 +1,54 @@ +package emailtemplates + +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 EmailTemplateGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EmailTemplateContract +} + +// EmailTemplateGet ... +func (c EmailTemplatesClient) EmailTemplateGet(ctx context.Context, id TemplateId) (result EmailTemplateGetOperationResponse, 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 EmailTemplateContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplates/method_emailtemplategetentitytag.go b/resource-manager/apimanagement/2024-05-01/emailtemplates/method_emailtemplategetentitytag.go new file mode 100644 index 00000000000..fd7e5616549 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplates/method_emailtemplategetentitytag.go @@ -0,0 +1,46 @@ +package emailtemplates + +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 EmailTemplateGetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// EmailTemplateGetEntityTag ... +func (c EmailTemplatesClient) EmailTemplateGetEntityTag(ctx context.Context, id TemplateId) (result EmailTemplateGetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplates/method_emailtemplateupdate.go b/resource-manager/apimanagement/2024-05-01/emailtemplates/method_emailtemplateupdate.go new file mode 100644 index 00000000000..6870b6a5cc8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplates/method_emailtemplateupdate.go @@ -0,0 +1,87 @@ +package emailtemplates + +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 EmailTemplateUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EmailTemplateContract +} + +type EmailTemplateUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultEmailTemplateUpdateOperationOptions() EmailTemplateUpdateOperationOptions { + return EmailTemplateUpdateOperationOptions{} +} + +func (o EmailTemplateUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o EmailTemplateUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o EmailTemplateUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// EmailTemplateUpdate ... +func (c EmailTemplatesClient) EmailTemplateUpdate(ctx context.Context, id TemplateId, input EmailTemplateUpdateParameters, options EmailTemplateUpdateOperationOptions) (result EmailTemplateUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 EmailTemplateContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplates/model_emailtemplatecontract.go b/resource-manager/apimanagement/2024-05-01/emailtemplates/model_emailtemplatecontract.go new file mode 100644 index 00000000000..185b3b6daf6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplates/model_emailtemplatecontract.go @@ -0,0 +1,11 @@ +package emailtemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EmailTemplateContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *EmailTemplateContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplates/model_emailtemplatecontractproperties.go b/resource-manager/apimanagement/2024-05-01/emailtemplates/model_emailtemplatecontractproperties.go new file mode 100644 index 00000000000..583e1fc7662 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplates/model_emailtemplatecontractproperties.go @@ -0,0 +1,13 @@ +package emailtemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EmailTemplateContractProperties struct { + Body string `json:"body"` + Description *string `json:"description,omitempty"` + IsDefault *bool `json:"isDefault,omitempty"` + Parameters *[]EmailTemplateParametersContractProperties `json:"parameters,omitempty"` + Subject string `json:"subject"` + Title *string `json:"title,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplates/model_emailtemplateparameterscontractproperties.go b/resource-manager/apimanagement/2024-05-01/emailtemplates/model_emailtemplateparameterscontractproperties.go new file mode 100644 index 00000000000..9b416504c7d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplates/model_emailtemplateparameterscontractproperties.go @@ -0,0 +1,10 @@ +package emailtemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EmailTemplateParametersContractProperties struct { + Description *string `json:"description,omitempty"` + Name *string `json:"name,omitempty"` + Title *string `json:"title,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplates/model_emailtemplateupdateparameterproperties.go b/resource-manager/apimanagement/2024-05-01/emailtemplates/model_emailtemplateupdateparameterproperties.go new file mode 100644 index 00000000000..a0d7fa1cde1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplates/model_emailtemplateupdateparameterproperties.go @@ -0,0 +1,12 @@ +package emailtemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EmailTemplateUpdateParameterProperties struct { + Body *string `json:"body,omitempty"` + Description *string `json:"description,omitempty"` + Parameters *[]EmailTemplateParametersContractProperties `json:"parameters,omitempty"` + Subject *string `json:"subject,omitempty"` + Title *string `json:"title,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplates/model_emailtemplateupdateparameters.go b/resource-manager/apimanagement/2024-05-01/emailtemplates/model_emailtemplateupdateparameters.go new file mode 100644 index 00000000000..d6fbb25c10b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplates/model_emailtemplateupdateparameters.go @@ -0,0 +1,8 @@ +package emailtemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EmailTemplateUpdateParameters struct { + Properties *EmailTemplateUpdateParameterProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/emailtemplates/version.go b/resource-manager/apimanagement/2024-05-01/emailtemplates/version.go new file mode 100644 index 00000000000..93aa1c7f50c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/emailtemplates/version.go @@ -0,0 +1,12 @@ +package emailtemplates + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/emailtemplates/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/gateway/README.md b/resource-manager/apimanagement/2024-05-01/gateway/README.md new file mode 100644 index 00000000000..4fb464a4641 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gateway/README.md @@ -0,0 +1,127 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gateway` Documentation + +The `gateway` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gateway" +``` + + +### Client Initialization + +```go +client := gateway.NewGatewayClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GatewayClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := gateway.NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue") + +payload := gateway.GatewayContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, gateway.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GatewayClient.Delete` + +```go +ctx := context.TODO() +id := gateway.NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue") + +read, err := client.Delete(ctx, id, gateway.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GatewayClient.Get` + +```go +ctx := context.TODO() +id := gateway.NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue") + +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: `GatewayClient.GetEntityTag` + +```go +ctx := context.TODO() +id := gateway.NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GatewayClient.ListByService` + +```go +ctx := context.TODO() +id := gateway.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, gateway.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, gateway.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `GatewayClient.Update` + +```go +ctx := context.TODO() +id := gateway.NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue") + +payload := gateway.GatewayContract{ + // ... +} + + +read, err := client.Update(ctx, id, payload, gateway.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/gateway/client.go b/resource-manager/apimanagement/2024-05-01/gateway/client.go new file mode 100644 index 00000000000..0d22b6f29bb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gateway/client.go @@ -0,0 +1,26 @@ +package gateway + +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 GatewayClient struct { + Client *resourcemanager.Client +} + +func NewGatewayClientWithBaseURI(sdkApi sdkEnv.Api) (*GatewayClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "gateway", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GatewayClient: %+v", err) + } + + return &GatewayClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/gateway/id_service.go b/resource-manager/apimanagement/2024-05-01/gateway/id_service.go new file mode 100644 index 00000000000..dbfd6735feb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gateway/id_service.go @@ -0,0 +1,130 @@ +package gateway + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/gateway/id_service_test.go b/resource-manager/apimanagement/2024-05-01/gateway/id_service_test.go new file mode 100644 index 00000000000..a535223581b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gateway/id_service_test.go @@ -0,0 +1,282 @@ +package gateway + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/gateway/id_servicegateway.go b/resource-manager/apimanagement/2024-05-01/gateway/id_servicegateway.go new file mode 100644 index 00000000000..f17eb16b13f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gateway/id_servicegateway.go @@ -0,0 +1,139 @@ +package gateway + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceGatewayId{}) +} + +var _ resourceids.ResourceId = &ServiceGatewayId{} + +// ServiceGatewayId is a struct representing the Resource ID for a Service Gateway +type ServiceGatewayId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + GatewayId string +} + +// NewServiceGatewayID returns a new ServiceGatewayId struct +func NewServiceGatewayID(subscriptionId string, resourceGroupName string, serviceName string, gatewayId string) ServiceGatewayId { + return ServiceGatewayId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + GatewayId: gatewayId, + } +} + +// ParseServiceGatewayID parses 'input' into a ServiceGatewayId +func ParseServiceGatewayID(input string) (*ServiceGatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceGatewayId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceGatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceGatewayIDInsensitively parses 'input' case-insensitively into a ServiceGatewayId +// note: this method should only be used for API response data and not user input +func ParseServiceGatewayIDInsensitively(input string) (*ServiceGatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceGatewayId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceGatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceGatewayId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.GatewayId, ok = input.Parsed["gatewayId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "gatewayId", input) + } + + return nil +} + +// ValidateServiceGatewayID checks that 'input' can be parsed as a Service Gateway ID +func ValidateServiceGatewayID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceGatewayID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service Gateway ID +func (id ServiceGatewayId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/gateways/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.GatewayId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service Gateway ID +func (id ServiceGatewayId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticGateways", "gateways", "gateways"), + resourceids.UserSpecifiedSegment("gatewayId", "gatewayIdValue"), + } +} + +// String returns a human-readable description of this Service Gateway ID +func (id ServiceGatewayId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Gateway: %q", id.GatewayId), + } + return fmt.Sprintf("Service Gateway (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/gateway/id_servicegateway_test.go b/resource-manager/apimanagement/2024-05-01/gateway/id_servicegateway_test.go new file mode 100644 index 00000000000..f2497cf3186 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gateway/id_servicegateway_test.go @@ -0,0 +1,327 @@ +package gateway + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceGatewayId{} + +func TestNewServiceGatewayID(t *testing.T) { + id := NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.GatewayId != "gatewayIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'GatewayId'", id.GatewayId, "gatewayIdValue") + } +} + +func TestFormatServiceGatewayID(t *testing.T) { + actual := NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceGatewayID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceGatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceGatewayID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + } +} + +func TestParseServiceGatewayIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceGatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + GatewayId: "gAtEwAyIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceGatewayIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + } +} + +func TestSegmentsForServiceGatewayId(t *testing.T) { + segments := ServiceGatewayId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceGatewayId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/gateway/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/gateway/method_createorupdate.go new file mode 100644 index 00000000000..729223eb676 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gateway/method_createorupdate.go @@ -0,0 +1,88 @@ +package gateway + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GatewayContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c GatewayClient) CreateOrUpdate(ctx context.Context, id ServiceGatewayId, input GatewayContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 GatewayContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gateway/method_delete.go b/resource-manager/apimanagement/2024-05-01/gateway/method_delete.go new file mode 100644 index 00000000000..2392197e1cf --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gateway/method_delete.go @@ -0,0 +1,76 @@ +package gateway + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c GatewayClient) Delete(ctx context.Context, id ServiceGatewayId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gateway/method_get.go b/resource-manager/apimanagement/2024-05-01/gateway/method_get.go new file mode 100644 index 00000000000..f774d19cc28 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gateway/method_get.go @@ -0,0 +1,54 @@ +package gateway + +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 *GatewayContract +} + +// Get ... +func (c GatewayClient) Get(ctx context.Context, id ServiceGatewayId) (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 GatewayContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gateway/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/gateway/method_getentitytag.go new file mode 100644 index 00000000000..dacdcc9e20a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gateway/method_getentitytag.go @@ -0,0 +1,46 @@ +package gateway + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c GatewayClient) GetEntityTag(ctx context.Context, id ServiceGatewayId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gateway/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/gateway/method_listbyservice.go new file mode 100644 index 00000000000..182f1a1be3b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gateway/method_listbyservice.go @@ -0,0 +1,141 @@ +package gateway + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GatewayContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []GatewayContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c GatewayClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/gateways", 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 *[]GatewayContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c GatewayClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, GatewayContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c GatewayClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate GatewayContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]GatewayContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gateway/method_update.go b/resource-manager/apimanagement/2024-05-01/gateway/method_update.go new file mode 100644 index 00000000000..f2bb1be8ff7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gateway/method_update.go @@ -0,0 +1,87 @@ +package gateway + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GatewayContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c GatewayClient) Update(ctx context.Context, id ServiceGatewayId, input GatewayContract, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 GatewayContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gateway/model_gatewaycontract.go b/resource-manager/apimanagement/2024-05-01/gateway/model_gatewaycontract.go new file mode 100644 index 00000000000..a39a34cac7f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gateway/model_gatewaycontract.go @@ -0,0 +1,11 @@ +package gateway + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewayContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *GatewayContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/gateway/model_gatewaycontractproperties.go b/resource-manager/apimanagement/2024-05-01/gateway/model_gatewaycontractproperties.go new file mode 100644 index 00000000000..5f103c064ef --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gateway/model_gatewaycontractproperties.go @@ -0,0 +1,9 @@ +package gateway + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewayContractProperties struct { + Description *string `json:"description,omitempty"` + LocationData *ResourceLocationDataContract `json:"locationData,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/gateway/model_resourcelocationdatacontract.go b/resource-manager/apimanagement/2024-05-01/gateway/model_resourcelocationdatacontract.go new file mode 100644 index 00000000000..75a50900788 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gateway/model_resourcelocationdatacontract.go @@ -0,0 +1,11 @@ +package gateway + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceLocationDataContract struct { + City *string `json:"city,omitempty"` + CountryOrRegion *string `json:"countryOrRegion,omitempty"` + District *string `json:"district,omitempty"` + Name string `json:"name"` +} diff --git a/resource-manager/apimanagement/2024-05-01/gateway/predicates.go b/resource-manager/apimanagement/2024-05-01/gateway/predicates.go new file mode 100644 index 00000000000..e3df21dd4c0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gateway/predicates.go @@ -0,0 +1,27 @@ +package gateway + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewayContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p GatewayContractOperationPredicate) Matches(input GatewayContract) 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/apimanagement/2024-05-01/gateway/version.go b/resource-manager/apimanagement/2024-05-01/gateway/version.go new file mode 100644 index 00000000000..0aa557ffdfe --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gateway/version.go @@ -0,0 +1,12 @@ +package gateway + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/gateway/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayapi/README.md b/resource-manager/apimanagement/2024-05-01/gatewayapi/README.md new file mode 100644 index 00000000000..ccdab2acd02 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayapi/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewayapi` Documentation + +The `gatewayapi` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewayapi" +``` + + +### Client Initialization + +```go +client := gatewayapi.NewGatewayApiClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GatewayApiClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := gatewayapi.NewGatewayApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue", "apiIdValue") + +payload := gatewayapi.AssociationContract{ + // ... +} + + +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: `GatewayApiClient.Delete` + +```go +ctx := context.TODO() +id := gatewayapi.NewGatewayApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue", "apiIdValue") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GatewayApiClient.GetEntityTag` + +```go +ctx := context.TODO() +id := gatewayapi.NewGatewayApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue", "apiIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GatewayApiClient.ListByService` + +```go +ctx := context.TODO() +id := gatewayapi.NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue") + +// alternatively `client.ListByService(ctx, id, gatewayapi.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, gatewayapi.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/gatewayapi/client.go b/resource-manager/apimanagement/2024-05-01/gatewayapi/client.go new file mode 100644 index 00000000000..6f88d7098fd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayapi/client.go @@ -0,0 +1,26 @@ +package gatewayapi + +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 GatewayApiClient struct { + Client *resourcemanager.Client +} + +func NewGatewayApiClientWithBaseURI(sdkApi sdkEnv.Api) (*GatewayApiClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "gatewayapi", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GatewayApiClient: %+v", err) + } + + return &GatewayApiClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayapi/constants.go b/resource-manager/apimanagement/2024-05-01/gatewayapi/constants.go new file mode 100644 index 00000000000..221f18de037 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayapi/constants.go @@ -0,0 +1,233 @@ +package gatewayapi + +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 ApiType string + +const ( + ApiTypeGraphql ApiType = "graphql" + ApiTypeGrpc ApiType = "grpc" + ApiTypeHTTP ApiType = "http" + ApiTypeOdata ApiType = "odata" + ApiTypeSoap ApiType = "soap" + ApiTypeWebsocket ApiType = "websocket" +) + +func PossibleValuesForApiType() []string { + return []string{ + string(ApiTypeGraphql), + string(ApiTypeGrpc), + string(ApiTypeHTTP), + string(ApiTypeOdata), + string(ApiTypeSoap), + string(ApiTypeWebsocket), + } +} + +func (s *ApiType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseApiType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseApiType(input string) (*ApiType, error) { + vals := map[string]ApiType{ + "graphql": ApiTypeGraphql, + "grpc": ApiTypeGrpc, + "http": ApiTypeHTTP, + "odata": ApiTypeOdata, + "soap": ApiTypeSoap, + "websocket": ApiTypeWebsocket, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ApiType(input) + return &out, nil +} + +type BearerTokenSendingMethods string + +const ( + BearerTokenSendingMethodsAuthorizationHeader BearerTokenSendingMethods = "authorizationHeader" + BearerTokenSendingMethodsQuery BearerTokenSendingMethods = "query" +) + +func PossibleValuesForBearerTokenSendingMethods() []string { + return []string{ + string(BearerTokenSendingMethodsAuthorizationHeader), + string(BearerTokenSendingMethodsQuery), + } +} + +func (s *BearerTokenSendingMethods) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBearerTokenSendingMethods(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBearerTokenSendingMethods(input string) (*BearerTokenSendingMethods, error) { + vals := map[string]BearerTokenSendingMethods{ + "authorizationheader": BearerTokenSendingMethodsAuthorizationHeader, + "query": BearerTokenSendingMethodsQuery, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BearerTokenSendingMethods(input) + return &out, nil +} + +type Protocol string + +const ( + ProtocolHTTP Protocol = "http" + ProtocolHTTPS Protocol = "https" + ProtocolWs Protocol = "ws" + ProtocolWss Protocol = "wss" +) + +func PossibleValuesForProtocol() []string { + return []string{ + string(ProtocolHTTP), + string(ProtocolHTTPS), + string(ProtocolWs), + string(ProtocolWss), + } +} + +func (s *Protocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProtocol(input string) (*Protocol, error) { + vals := map[string]Protocol{ + "http": ProtocolHTTP, + "https": ProtocolHTTPS, + "ws": ProtocolWs, + "wss": ProtocolWss, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Protocol(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCreated ProvisioningState = "created" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCreated), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "created": ProvisioningStateCreated, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type VersioningScheme string + +const ( + VersioningSchemeHeader VersioningScheme = "Header" + VersioningSchemeQuery VersioningScheme = "Query" + VersioningSchemeSegment VersioningScheme = "Segment" +) + +func PossibleValuesForVersioningScheme() []string { + return []string{ + string(VersioningSchemeHeader), + string(VersioningSchemeQuery), + string(VersioningSchemeSegment), + } +} + +func (s *VersioningScheme) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVersioningScheme(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVersioningScheme(input string) (*VersioningScheme, error) { + vals := map[string]VersioningScheme{ + "header": VersioningSchemeHeader, + "query": VersioningSchemeQuery, + "segment": VersioningSchemeSegment, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VersioningScheme(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayapi/id_gatewayapi.go b/resource-manager/apimanagement/2024-05-01/gatewayapi/id_gatewayapi.go new file mode 100644 index 00000000000..1780b205bde --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayapi/id_gatewayapi.go @@ -0,0 +1,148 @@ +package gatewayapi + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&GatewayApiId{}) +} + +var _ resourceids.ResourceId = &GatewayApiId{} + +// GatewayApiId is a struct representing the Resource ID for a Gateway Api +type GatewayApiId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + GatewayId string + ApiId string +} + +// NewGatewayApiID returns a new GatewayApiId struct +func NewGatewayApiID(subscriptionId string, resourceGroupName string, serviceName string, gatewayId string, apiId string) GatewayApiId { + return GatewayApiId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + GatewayId: gatewayId, + ApiId: apiId, + } +} + +// ParseGatewayApiID parses 'input' into a GatewayApiId +func ParseGatewayApiID(input string) (*GatewayApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&GatewayApiId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GatewayApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGatewayApiIDInsensitively parses 'input' case-insensitively into a GatewayApiId +// note: this method should only be used for API response data and not user input +func ParseGatewayApiIDInsensitively(input string) (*GatewayApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&GatewayApiId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GatewayApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GatewayApiId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.GatewayId, ok = input.Parsed["gatewayId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "gatewayId", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + return nil +} + +// ValidateGatewayApiID checks that 'input' can be parsed as a Gateway Api ID +func ValidateGatewayApiID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseGatewayApiID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Gateway Api ID +func (id GatewayApiId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/gateways/%s/apis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.GatewayId, id.ApiId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Gateway Api ID +func (id GatewayApiId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticGateways", "gateways", "gateways"), + resourceids.UserSpecifiedSegment("gatewayId", "gatewayIdValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + } +} + +// String returns a human-readable description of this Gateway Api ID +func (id GatewayApiId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Gateway: %q", id.GatewayId), + fmt.Sprintf("Api: %q", id.ApiId), + } + return fmt.Sprintf("Gateway Api (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayapi/id_gatewayapi_test.go b/resource-manager/apimanagement/2024-05-01/gatewayapi/id_gatewayapi_test.go new file mode 100644 index 00000000000..e6eef892628 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayapi/id_gatewayapi_test.go @@ -0,0 +1,372 @@ +package gatewayapi + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GatewayApiId{} + +func TestNewGatewayApiID(t *testing.T) { + id := NewGatewayApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue", "apiIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.GatewayId != "gatewayIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'GatewayId'", id.GatewayId, "gatewayIdValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } +} + +func TestFormatGatewayApiID(t *testing.T) { + actual := NewGatewayApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue", "apiIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/apis/apiIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGatewayApiID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GatewayApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/apis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/apis/apiIdValue", + Expected: &GatewayApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/apis/apiIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGatewayApiID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestParseGatewayApiIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GatewayApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE/aPiS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/apis/apiIdValue", + Expected: &GatewayApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/apis/apiIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE/aPiS/aPiIdVaLuE", + Expected: &GatewayApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + GatewayId: "gAtEwAyIdVaLuE", + ApiId: "aPiIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE/aPiS/aPiIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGatewayApiIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestSegmentsForGatewayApiId(t *testing.T) { + segments := GatewayApiId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GatewayApiId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayapi/id_servicegateway.go b/resource-manager/apimanagement/2024-05-01/gatewayapi/id_servicegateway.go new file mode 100644 index 00000000000..381375795e2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayapi/id_servicegateway.go @@ -0,0 +1,139 @@ +package gatewayapi + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceGatewayId{}) +} + +var _ resourceids.ResourceId = &ServiceGatewayId{} + +// ServiceGatewayId is a struct representing the Resource ID for a Service Gateway +type ServiceGatewayId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + GatewayId string +} + +// NewServiceGatewayID returns a new ServiceGatewayId struct +func NewServiceGatewayID(subscriptionId string, resourceGroupName string, serviceName string, gatewayId string) ServiceGatewayId { + return ServiceGatewayId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + GatewayId: gatewayId, + } +} + +// ParseServiceGatewayID parses 'input' into a ServiceGatewayId +func ParseServiceGatewayID(input string) (*ServiceGatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceGatewayId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceGatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceGatewayIDInsensitively parses 'input' case-insensitively into a ServiceGatewayId +// note: this method should only be used for API response data and not user input +func ParseServiceGatewayIDInsensitively(input string) (*ServiceGatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceGatewayId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceGatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceGatewayId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.GatewayId, ok = input.Parsed["gatewayId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "gatewayId", input) + } + + return nil +} + +// ValidateServiceGatewayID checks that 'input' can be parsed as a Service Gateway ID +func ValidateServiceGatewayID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceGatewayID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service Gateway ID +func (id ServiceGatewayId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/gateways/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.GatewayId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service Gateway ID +func (id ServiceGatewayId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticGateways", "gateways", "gateways"), + resourceids.UserSpecifiedSegment("gatewayId", "gatewayIdValue"), + } +} + +// String returns a human-readable description of this Service Gateway ID +func (id ServiceGatewayId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Gateway: %q", id.GatewayId), + } + return fmt.Sprintf("Service Gateway (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayapi/id_servicegateway_test.go b/resource-manager/apimanagement/2024-05-01/gatewayapi/id_servicegateway_test.go new file mode 100644 index 00000000000..219f9ed16c1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayapi/id_servicegateway_test.go @@ -0,0 +1,327 @@ +package gatewayapi + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceGatewayId{} + +func TestNewServiceGatewayID(t *testing.T) { + id := NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.GatewayId != "gatewayIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'GatewayId'", id.GatewayId, "gatewayIdValue") + } +} + +func TestFormatServiceGatewayID(t *testing.T) { + actual := NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceGatewayID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceGatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceGatewayID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + } +} + +func TestParseServiceGatewayIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceGatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + GatewayId: "gAtEwAyIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceGatewayIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + } +} + +func TestSegmentsForServiceGatewayId(t *testing.T) { + segments := ServiceGatewayId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceGatewayId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayapi/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/gatewayapi/method_createorupdate.go new file mode 100644 index 00000000000..5af86c5ab69 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayapi/method_createorupdate.go @@ -0,0 +1,59 @@ +package gatewayapi + +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 *ApiContract +} + +// CreateOrUpdate ... +func (c GatewayApiClient) CreateOrUpdate(ctx context.Context, id GatewayApiId, input AssociationContract) (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 ApiContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayapi/method_delete.go b/resource-manager/apimanagement/2024-05-01/gatewayapi/method_delete.go new file mode 100644 index 00000000000..293176f784a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayapi/method_delete.go @@ -0,0 +1,47 @@ +package gatewayapi + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c GatewayApiClient) Delete(ctx context.Context, id GatewayApiId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayapi/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/gatewayapi/method_getentitytag.go new file mode 100644 index 00000000000..e14c0b61f72 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayapi/method_getentitytag.go @@ -0,0 +1,46 @@ +package gatewayapi + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c GatewayApiClient) GetEntityTag(ctx context.Context, id GatewayApiId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayapi/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/gatewayapi/method_listbyservice.go new file mode 100644 index 00000000000..1b690a95d5e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayapi/method_listbyservice.go @@ -0,0 +1,141 @@ +package gatewayapi + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ApiContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ApiContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c GatewayApiClient) ListByService(ctx context.Context, id ServiceGatewayId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/apis", 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 *[]ApiContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c GatewayApiClient) ListByServiceComplete(ctx context.Context, id ServiceGatewayId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, ApiContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c GatewayApiClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceGatewayId, options ListByServiceOperationOptions, predicate ApiContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]ApiContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayapi/model_apicontactinformation.go b/resource-manager/apimanagement/2024-05-01/gatewayapi/model_apicontactinformation.go new file mode 100644 index 00000000000..b1c3688ef45 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayapi/model_apicontactinformation.go @@ -0,0 +1,10 @@ +package gatewayapi + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiContactInformation struct { + Email *string `json:"email,omitempty"` + Name *string `json:"name,omitempty"` + Url *string `json:"url,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayapi/model_apicontract.go b/resource-manager/apimanagement/2024-05-01/gatewayapi/model_apicontract.go new file mode 100644 index 00000000000..fe7b4bd59da --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayapi/model_apicontract.go @@ -0,0 +1,11 @@ +package gatewayapi + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ApiContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayapi/model_apicontractproperties.go b/resource-manager/apimanagement/2024-05-01/gatewayapi/model_apicontractproperties.go new file mode 100644 index 00000000000..54fd88900fd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayapi/model_apicontractproperties.go @@ -0,0 +1,29 @@ +package gatewayapi + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiContractProperties struct { + ApiRevision *string `json:"apiRevision,omitempty"` + ApiRevisionDescription *string `json:"apiRevisionDescription,omitempty"` + ApiVersion *string `json:"apiVersion,omitempty"` + ApiVersionDescription *string `json:"apiVersionDescription,omitempty"` + ApiVersionSet *ApiVersionSetContractDetails `json:"apiVersionSet,omitempty"` + ApiVersionSetId *string `json:"apiVersionSetId,omitempty"` + AuthenticationSettings *AuthenticationSettingsContract `json:"authenticationSettings,omitempty"` + Contact *ApiContactInformation `json:"contact,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + IsCurrent *bool `json:"isCurrent,omitempty"` + IsOnline *bool `json:"isOnline,omitempty"` + License *ApiLicenseInformation `json:"license,omitempty"` + Path string `json:"path"` + Protocols *[]Protocol `json:"protocols,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + ServiceUrl *string `json:"serviceUrl,omitempty"` + SourceApiId *string `json:"sourceApiId,omitempty"` + SubscriptionKeyParameterNames *SubscriptionKeyParameterNamesContract `json:"subscriptionKeyParameterNames,omitempty"` + SubscriptionRequired *bool `json:"subscriptionRequired,omitempty"` + TermsOfServiceUrl *string `json:"termsOfServiceUrl,omitempty"` + Type *ApiType `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayapi/model_apilicenseinformation.go b/resource-manager/apimanagement/2024-05-01/gatewayapi/model_apilicenseinformation.go new file mode 100644 index 00000000000..287962be3e7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayapi/model_apilicenseinformation.go @@ -0,0 +1,9 @@ +package gatewayapi + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiLicenseInformation struct { + Name *string `json:"name,omitempty"` + Url *string `json:"url,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayapi/model_apiversionsetcontractdetails.go b/resource-manager/apimanagement/2024-05-01/gatewayapi/model_apiversionsetcontractdetails.go new file mode 100644 index 00000000000..7bbb4ab4222 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayapi/model_apiversionsetcontractdetails.go @@ -0,0 +1,13 @@ +package gatewayapi + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiVersionSetContractDetails struct { + Description *string `json:"description,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + VersionHeaderName *string `json:"versionHeaderName,omitempty"` + VersionQueryName *string `json:"versionQueryName,omitempty"` + VersioningScheme *VersioningScheme `json:"versioningScheme,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayapi/model_associationcontract.go b/resource-manager/apimanagement/2024-05-01/gatewayapi/model_associationcontract.go new file mode 100644 index 00000000000..8ec8abebbf5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayapi/model_associationcontract.go @@ -0,0 +1,11 @@ +package gatewayapi + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AssociationContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AssociationContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayapi/model_associationcontractproperties.go b/resource-manager/apimanagement/2024-05-01/gatewayapi/model_associationcontractproperties.go new file mode 100644 index 00000000000..c1b4895fd81 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayapi/model_associationcontractproperties.go @@ -0,0 +1,8 @@ +package gatewayapi + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AssociationContractProperties struct { + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayapi/model_authenticationsettingscontract.go b/resource-manager/apimanagement/2024-05-01/gatewayapi/model_authenticationsettingscontract.go new file mode 100644 index 00000000000..55b2d9086f3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayapi/model_authenticationsettingscontract.go @@ -0,0 +1,11 @@ +package gatewayapi + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthenticationSettingsContract struct { + OAuth2 *OAuth2AuthenticationSettingsContract `json:"oAuth2,omitempty"` + OAuth2AuthenticationSettings *[]OAuth2AuthenticationSettingsContract `json:"oAuth2AuthenticationSettings,omitempty"` + Openid *OpenIdAuthenticationSettingsContract `json:"openid,omitempty"` + OpenidAuthenticationSettings *[]OpenIdAuthenticationSettingsContract `json:"openidAuthenticationSettings,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayapi/model_oauth2authenticationsettingscontract.go b/resource-manager/apimanagement/2024-05-01/gatewayapi/model_oauth2authenticationsettingscontract.go new file mode 100644 index 00000000000..1362d06b873 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayapi/model_oauth2authenticationsettingscontract.go @@ -0,0 +1,9 @@ +package gatewayapi + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OAuth2AuthenticationSettingsContract struct { + AuthorizationServerId *string `json:"authorizationServerId,omitempty"` + Scope *string `json:"scope,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayapi/model_openidauthenticationsettingscontract.go b/resource-manager/apimanagement/2024-05-01/gatewayapi/model_openidauthenticationsettingscontract.go new file mode 100644 index 00000000000..4bd4b6e78bc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayapi/model_openidauthenticationsettingscontract.go @@ -0,0 +1,9 @@ +package gatewayapi + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OpenIdAuthenticationSettingsContract struct { + BearerTokenSendingMethods *[]BearerTokenSendingMethods `json:"bearerTokenSendingMethods,omitempty"` + OpenidProviderId *string `json:"openidProviderId,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayapi/model_subscriptionkeyparameternamescontract.go b/resource-manager/apimanagement/2024-05-01/gatewayapi/model_subscriptionkeyparameternamescontract.go new file mode 100644 index 00000000000..2548329e0b9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayapi/model_subscriptionkeyparameternamescontract.go @@ -0,0 +1,9 @@ +package gatewayapi + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionKeyParameterNamesContract struct { + Header *string `json:"header,omitempty"` + Query *string `json:"query,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayapi/predicates.go b/resource-manager/apimanagement/2024-05-01/gatewayapi/predicates.go new file mode 100644 index 00000000000..46947f21478 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayapi/predicates.go @@ -0,0 +1,27 @@ +package gatewayapi + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ApiContractOperationPredicate) Matches(input ApiContract) 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/apimanagement/2024-05-01/gatewayapi/version.go b/resource-manager/apimanagement/2024-05-01/gatewayapi/version.go new file mode 100644 index 00000000000..0be52c4c37c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayapi/version.go @@ -0,0 +1,12 @@ +package gatewayapi + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/gatewayapi/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/README.md b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/README.md new file mode 100644 index 00000000000..e1d9abba06c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/README.md @@ -0,0 +1,106 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority` Documentation + +The `gatewaycertificateauthority` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority" +``` + + +### Client Initialization + +```go +client := gatewaycertificateauthority.NewGatewayCertificateAuthorityClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GatewayCertificateAuthorityClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := gatewaycertificateauthority.NewCertificateAuthorityID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue", "certificateIdValue") + +payload := gatewaycertificateauthority.GatewayCertificateAuthorityContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, gatewaycertificateauthority.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GatewayCertificateAuthorityClient.Delete` + +```go +ctx := context.TODO() +id := gatewaycertificateauthority.NewCertificateAuthorityID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue", "certificateIdValue") + +read, err := client.Delete(ctx, id, gatewaycertificateauthority.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GatewayCertificateAuthorityClient.Get` + +```go +ctx := context.TODO() +id := gatewaycertificateauthority.NewCertificateAuthorityID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue", "certificateIdValue") + +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: `GatewayCertificateAuthorityClient.GetEntityTag` + +```go +ctx := context.TODO() +id := gatewaycertificateauthority.NewCertificateAuthorityID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue", "certificateIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GatewayCertificateAuthorityClient.ListByService` + +```go +ctx := context.TODO() +id := gatewaycertificateauthority.NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue") + +// alternatively `client.ListByService(ctx, id, gatewaycertificateauthority.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, gatewaycertificateauthority.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/client.go b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/client.go new file mode 100644 index 00000000000..82e3bc25dd6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/client.go @@ -0,0 +1,26 @@ +package gatewaycertificateauthority + +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 GatewayCertificateAuthorityClient struct { + Client *resourcemanager.Client +} + +func NewGatewayCertificateAuthorityClientWithBaseURI(sdkApi sdkEnv.Api) (*GatewayCertificateAuthorityClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "gatewaycertificateauthority", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GatewayCertificateAuthorityClient: %+v", err) + } + + return &GatewayCertificateAuthorityClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/id_certificateauthority.go b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/id_certificateauthority.go new file mode 100644 index 00000000000..1d7f6784836 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/id_certificateauthority.go @@ -0,0 +1,148 @@ +package gatewaycertificateauthority + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&CertificateAuthorityId{}) +} + +var _ resourceids.ResourceId = &CertificateAuthorityId{} + +// CertificateAuthorityId is a struct representing the Resource ID for a Certificate Authority +type CertificateAuthorityId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + GatewayId string + CertificateId string +} + +// NewCertificateAuthorityID returns a new CertificateAuthorityId struct +func NewCertificateAuthorityID(subscriptionId string, resourceGroupName string, serviceName string, gatewayId string, certificateId string) CertificateAuthorityId { + return CertificateAuthorityId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + GatewayId: gatewayId, + CertificateId: certificateId, + } +} + +// ParseCertificateAuthorityID parses 'input' into a CertificateAuthorityId +func ParseCertificateAuthorityID(input string) (*CertificateAuthorityId, error) { + parser := resourceids.NewParserFromResourceIdType(&CertificateAuthorityId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CertificateAuthorityId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseCertificateAuthorityIDInsensitively parses 'input' case-insensitively into a CertificateAuthorityId +// note: this method should only be used for API response data and not user input +func ParseCertificateAuthorityIDInsensitively(input string) (*CertificateAuthorityId, error) { + parser := resourceids.NewParserFromResourceIdType(&CertificateAuthorityId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CertificateAuthorityId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *CertificateAuthorityId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.GatewayId, ok = input.Parsed["gatewayId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "gatewayId", input) + } + + if id.CertificateId, ok = input.Parsed["certificateId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "certificateId", input) + } + + return nil +} + +// ValidateCertificateAuthorityID checks that 'input' can be parsed as a Certificate Authority ID +func ValidateCertificateAuthorityID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseCertificateAuthorityID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Certificate Authority ID +func (id CertificateAuthorityId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/gateways/%s/certificateAuthorities/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.GatewayId, id.CertificateId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Certificate Authority ID +func (id CertificateAuthorityId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticGateways", "gateways", "gateways"), + resourceids.UserSpecifiedSegment("gatewayId", "gatewayIdValue"), + resourceids.StaticSegment("staticCertificateAuthorities", "certificateAuthorities", "certificateAuthorities"), + resourceids.UserSpecifiedSegment("certificateId", "certificateIdValue"), + } +} + +// String returns a human-readable description of this Certificate Authority ID +func (id CertificateAuthorityId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Gateway: %q", id.GatewayId), + fmt.Sprintf("Certificate: %q", id.CertificateId), + } + return fmt.Sprintf("Certificate Authority (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/id_certificateauthority_test.go b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/id_certificateauthority_test.go new file mode 100644 index 00000000000..5a0bd918eb2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/id_certificateauthority_test.go @@ -0,0 +1,372 @@ +package gatewaycertificateauthority + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &CertificateAuthorityId{} + +func TestNewCertificateAuthorityID(t *testing.T) { + id := NewCertificateAuthorityID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue", "certificateIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.GatewayId != "gatewayIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'GatewayId'", id.GatewayId, "gatewayIdValue") + } + + if id.CertificateId != "certificateIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'CertificateId'", id.CertificateId, "certificateIdValue") + } +} + +func TestFormatCertificateAuthorityID(t *testing.T) { + actual := NewCertificateAuthorityID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue", "certificateIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/certificateAuthorities/certificateIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCertificateAuthorityID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CertificateAuthorityId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/certificateAuthorities", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/certificateAuthorities/certificateIdValue", + Expected: &CertificateAuthorityId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + CertificateId: "certificateIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/certificateAuthorities/certificateIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCertificateAuthorityID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + if actual.CertificateId != v.Expected.CertificateId { + t.Fatalf("Expected %q but got %q for CertificateId", v.Expected.CertificateId, actual.CertificateId) + } + + } +} + +func TestParseCertificateAuthorityIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CertificateAuthorityId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/certificateAuthorities", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE/cErTiFiCaTeAuThOrItIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/certificateAuthorities/certificateIdValue", + Expected: &CertificateAuthorityId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + CertificateId: "certificateIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/certificateAuthorities/certificateIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE/cErTiFiCaTeAuThOrItIeS/cErTiFiCaTeIdVaLuE", + Expected: &CertificateAuthorityId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + GatewayId: "gAtEwAyIdVaLuE", + CertificateId: "cErTiFiCaTeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE/cErTiFiCaTeAuThOrItIeS/cErTiFiCaTeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCertificateAuthorityIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + if actual.CertificateId != v.Expected.CertificateId { + t.Fatalf("Expected %q but got %q for CertificateId", v.Expected.CertificateId, actual.CertificateId) + } + + } +} + +func TestSegmentsForCertificateAuthorityId(t *testing.T) { + segments := CertificateAuthorityId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CertificateAuthorityId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/id_servicegateway.go b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/id_servicegateway.go new file mode 100644 index 00000000000..26b78ec931a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/id_servicegateway.go @@ -0,0 +1,139 @@ +package gatewaycertificateauthority + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceGatewayId{}) +} + +var _ resourceids.ResourceId = &ServiceGatewayId{} + +// ServiceGatewayId is a struct representing the Resource ID for a Service Gateway +type ServiceGatewayId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + GatewayId string +} + +// NewServiceGatewayID returns a new ServiceGatewayId struct +func NewServiceGatewayID(subscriptionId string, resourceGroupName string, serviceName string, gatewayId string) ServiceGatewayId { + return ServiceGatewayId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + GatewayId: gatewayId, + } +} + +// ParseServiceGatewayID parses 'input' into a ServiceGatewayId +func ParseServiceGatewayID(input string) (*ServiceGatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceGatewayId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceGatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceGatewayIDInsensitively parses 'input' case-insensitively into a ServiceGatewayId +// note: this method should only be used for API response data and not user input +func ParseServiceGatewayIDInsensitively(input string) (*ServiceGatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceGatewayId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceGatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceGatewayId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.GatewayId, ok = input.Parsed["gatewayId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "gatewayId", input) + } + + return nil +} + +// ValidateServiceGatewayID checks that 'input' can be parsed as a Service Gateway ID +func ValidateServiceGatewayID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceGatewayID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service Gateway ID +func (id ServiceGatewayId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/gateways/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.GatewayId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service Gateway ID +func (id ServiceGatewayId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticGateways", "gateways", "gateways"), + resourceids.UserSpecifiedSegment("gatewayId", "gatewayIdValue"), + } +} + +// String returns a human-readable description of this Service Gateway ID +func (id ServiceGatewayId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Gateway: %q", id.GatewayId), + } + return fmt.Sprintf("Service Gateway (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/id_servicegateway_test.go b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/id_servicegateway_test.go new file mode 100644 index 00000000000..63bbf1dd045 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/id_servicegateway_test.go @@ -0,0 +1,327 @@ +package gatewaycertificateauthority + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceGatewayId{} + +func TestNewServiceGatewayID(t *testing.T) { + id := NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.GatewayId != "gatewayIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'GatewayId'", id.GatewayId, "gatewayIdValue") + } +} + +func TestFormatServiceGatewayID(t *testing.T) { + actual := NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceGatewayID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceGatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceGatewayID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + } +} + +func TestParseServiceGatewayIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceGatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + GatewayId: "gAtEwAyIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceGatewayIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + } +} + +func TestSegmentsForServiceGatewayId(t *testing.T) { + segments := ServiceGatewayId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceGatewayId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/method_createorupdate.go new file mode 100644 index 00000000000..421099fff39 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/method_createorupdate.go @@ -0,0 +1,88 @@ +package gatewaycertificateauthority + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GatewayCertificateAuthorityContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c GatewayCertificateAuthorityClient) CreateOrUpdate(ctx context.Context, id CertificateAuthorityId, input GatewayCertificateAuthorityContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 GatewayCertificateAuthorityContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/method_delete.go b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/method_delete.go new file mode 100644 index 00000000000..a6b9d901d6b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/method_delete.go @@ -0,0 +1,76 @@ +package gatewaycertificateauthority + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c GatewayCertificateAuthorityClient) Delete(ctx context.Context, id CertificateAuthorityId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/method_get.go b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/method_get.go new file mode 100644 index 00000000000..2a8a3c51cfd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/method_get.go @@ -0,0 +1,54 @@ +package gatewaycertificateauthority + +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 *GatewayCertificateAuthorityContract +} + +// Get ... +func (c GatewayCertificateAuthorityClient) Get(ctx context.Context, id CertificateAuthorityId) (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 GatewayCertificateAuthorityContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/method_getentitytag.go new file mode 100644 index 00000000000..cc382dbb6d8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/method_getentitytag.go @@ -0,0 +1,46 @@ +package gatewaycertificateauthority + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c GatewayCertificateAuthorityClient) GetEntityTag(ctx context.Context, id CertificateAuthorityId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/method_listbyservice.go new file mode 100644 index 00000000000..b682c353d60 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/method_listbyservice.go @@ -0,0 +1,141 @@ +package gatewaycertificateauthority + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GatewayCertificateAuthorityContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []GatewayCertificateAuthorityContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c GatewayCertificateAuthorityClient) ListByService(ctx context.Context, id ServiceGatewayId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/certificateAuthorities", 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 *[]GatewayCertificateAuthorityContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c GatewayCertificateAuthorityClient) ListByServiceComplete(ctx context.Context, id ServiceGatewayId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, GatewayCertificateAuthorityContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c GatewayCertificateAuthorityClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceGatewayId, options ListByServiceOperationOptions, predicate GatewayCertificateAuthorityContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]GatewayCertificateAuthorityContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/model_gatewaycertificateauthoritycontract.go b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/model_gatewaycertificateauthoritycontract.go new file mode 100644 index 00000000000..c16f0cbeb3e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/model_gatewaycertificateauthoritycontract.go @@ -0,0 +1,11 @@ +package gatewaycertificateauthority + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewayCertificateAuthorityContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *GatewayCertificateAuthorityContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/model_gatewaycertificateauthoritycontractproperties.go b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/model_gatewaycertificateauthoritycontractproperties.go new file mode 100644 index 00000000000..204ec98b300 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/model_gatewaycertificateauthoritycontractproperties.go @@ -0,0 +1,8 @@ +package gatewaycertificateauthority + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewayCertificateAuthorityContractProperties struct { + IsTrusted *bool `json:"isTrusted,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/predicates.go b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/predicates.go new file mode 100644 index 00000000000..10927ccab9f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/predicates.go @@ -0,0 +1,27 @@ +package gatewaycertificateauthority + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewayCertificateAuthorityContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p GatewayCertificateAuthorityContractOperationPredicate) Matches(input GatewayCertificateAuthorityContract) 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/apimanagement/2024-05-01/gatewaycertificateauthority/version.go b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/version.go new file mode 100644 index 00000000000..3f9b6fc30e7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaycertificateauthority/version.go @@ -0,0 +1,12 @@ +package gatewaycertificateauthority + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/gatewaycertificateauthority/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/README.md b/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/README.md new file mode 100644 index 00000000000..c271076d50f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/README.md @@ -0,0 +1,41 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken` Documentation + +The `gatewaygeneratetoken` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken" +``` + + +### Client Initialization + +```go +client := gatewaygeneratetoken.NewGatewayGenerateTokenClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GatewayGenerateTokenClient.GatewayGenerateToken` + +```go +ctx := context.TODO() +id := gatewaygeneratetoken.NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue") + +payload := gatewaygeneratetoken.GatewayTokenRequestContract{ + // ... +} + + +read, err := client.GatewayGenerateToken(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/apimanagement/2024-05-01/gatewaygeneratetoken/client.go b/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/client.go new file mode 100644 index 00000000000..ea0ee9040c7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/client.go @@ -0,0 +1,26 @@ +package gatewaygeneratetoken + +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 GatewayGenerateTokenClient struct { + Client *resourcemanager.Client +} + +func NewGatewayGenerateTokenClientWithBaseURI(sdkApi sdkEnv.Api) (*GatewayGenerateTokenClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "gatewaygeneratetoken", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GatewayGenerateTokenClient: %+v", err) + } + + return &GatewayGenerateTokenClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/constants.go b/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/constants.go new file mode 100644 index 00000000000..23e4c225a32 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/constants.go @@ -0,0 +1,51 @@ +package gatewaygeneratetoken + +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 KeyType string + +const ( + KeyTypePrimary KeyType = "primary" + KeyTypeSecondary KeyType = "secondary" +) + +func PossibleValuesForKeyType() []string { + return []string{ + string(KeyTypePrimary), + string(KeyTypeSecondary), + } +} + +func (s *KeyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKeyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseKeyType(input string) (*KeyType, error) { + vals := map[string]KeyType{ + "primary": KeyTypePrimary, + "secondary": KeyTypeSecondary, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := KeyType(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/id_servicegateway.go b/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/id_servicegateway.go new file mode 100644 index 00000000000..53bee8e1890 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/id_servicegateway.go @@ -0,0 +1,139 @@ +package gatewaygeneratetoken + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceGatewayId{}) +} + +var _ resourceids.ResourceId = &ServiceGatewayId{} + +// ServiceGatewayId is a struct representing the Resource ID for a Service Gateway +type ServiceGatewayId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + GatewayId string +} + +// NewServiceGatewayID returns a new ServiceGatewayId struct +func NewServiceGatewayID(subscriptionId string, resourceGroupName string, serviceName string, gatewayId string) ServiceGatewayId { + return ServiceGatewayId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + GatewayId: gatewayId, + } +} + +// ParseServiceGatewayID parses 'input' into a ServiceGatewayId +func ParseServiceGatewayID(input string) (*ServiceGatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceGatewayId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceGatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceGatewayIDInsensitively parses 'input' case-insensitively into a ServiceGatewayId +// note: this method should only be used for API response data and not user input +func ParseServiceGatewayIDInsensitively(input string) (*ServiceGatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceGatewayId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceGatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceGatewayId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.GatewayId, ok = input.Parsed["gatewayId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "gatewayId", input) + } + + return nil +} + +// ValidateServiceGatewayID checks that 'input' can be parsed as a Service Gateway ID +func ValidateServiceGatewayID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceGatewayID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service Gateway ID +func (id ServiceGatewayId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/gateways/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.GatewayId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service Gateway ID +func (id ServiceGatewayId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticGateways", "gateways", "gateways"), + resourceids.UserSpecifiedSegment("gatewayId", "gatewayIdValue"), + } +} + +// String returns a human-readable description of this Service Gateway ID +func (id ServiceGatewayId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Gateway: %q", id.GatewayId), + } + return fmt.Sprintf("Service Gateway (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/id_servicegateway_test.go b/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/id_servicegateway_test.go new file mode 100644 index 00000000000..cc348b3d292 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/id_servicegateway_test.go @@ -0,0 +1,327 @@ +package gatewaygeneratetoken + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceGatewayId{} + +func TestNewServiceGatewayID(t *testing.T) { + id := NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.GatewayId != "gatewayIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'GatewayId'", id.GatewayId, "gatewayIdValue") + } +} + +func TestFormatServiceGatewayID(t *testing.T) { + actual := NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceGatewayID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceGatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceGatewayID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + } +} + +func TestParseServiceGatewayIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceGatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + GatewayId: "gAtEwAyIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceGatewayIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + } +} + +func TestSegmentsForServiceGatewayId(t *testing.T) { + segments := ServiceGatewayId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceGatewayId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/method_gatewaygeneratetoken.go b/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/method_gatewaygeneratetoken.go new file mode 100644 index 00000000000..c9b2d8153e0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/method_gatewaygeneratetoken.go @@ -0,0 +1,59 @@ +package gatewaygeneratetoken + +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 GatewayGenerateTokenOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GatewayTokenContract +} + +// GatewayGenerateToken ... +func (c GatewayGenerateTokenClient) GatewayGenerateToken(ctx context.Context, id ServiceGatewayId, input GatewayTokenRequestContract) (result GatewayGenerateTokenOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/generateToken", 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 GatewayTokenContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/model_gatewaytokencontract.go b/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/model_gatewaytokencontract.go new file mode 100644 index 00000000000..72823a55fa9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/model_gatewaytokencontract.go @@ -0,0 +1,8 @@ +package gatewaygeneratetoken + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewayTokenContract struct { + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/model_gatewaytokenrequestcontract.go b/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/model_gatewaytokenrequestcontract.go new file mode 100644 index 00000000000..961e679f9ec --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/model_gatewaytokenrequestcontract.go @@ -0,0 +1,24 @@ +package gatewaygeneratetoken + +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 GatewayTokenRequestContract struct { + Expiry string `json:"expiry"` + KeyType KeyType `json:"keyType"` +} + +func (o *GatewayTokenRequestContract) GetExpiryAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.Expiry, "2006-01-02T15:04:05Z07:00") +} + +func (o *GatewayTokenRequestContract) SetExpiryAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Expiry = formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/version.go b/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/version.go new file mode 100644 index 00000000000..05c90e83cf0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaygeneratetoken/version.go @@ -0,0 +1,12 @@ +package gatewaygeneratetoken + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/gatewaygeneratetoken/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/README.md b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/README.md new file mode 100644 index 00000000000..097c722c310 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/README.md @@ -0,0 +1,106 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration` Documentation + +The `gatewayhostnameconfiguration` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration" +``` + + +### Client Initialization + +```go +client := gatewayhostnameconfiguration.NewGatewayHostnameConfigurationClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GatewayHostnameConfigurationClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := gatewayhostnameconfiguration.NewHostnameConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue", "hcIdValue") + +payload := gatewayhostnameconfiguration.GatewayHostnameConfigurationContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, gatewayhostnameconfiguration.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GatewayHostnameConfigurationClient.Delete` + +```go +ctx := context.TODO() +id := gatewayhostnameconfiguration.NewHostnameConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue", "hcIdValue") + +read, err := client.Delete(ctx, id, gatewayhostnameconfiguration.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GatewayHostnameConfigurationClient.Get` + +```go +ctx := context.TODO() +id := gatewayhostnameconfiguration.NewHostnameConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue", "hcIdValue") + +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: `GatewayHostnameConfigurationClient.GetEntityTag` + +```go +ctx := context.TODO() +id := gatewayhostnameconfiguration.NewHostnameConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue", "hcIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GatewayHostnameConfigurationClient.ListByService` + +```go +ctx := context.TODO() +id := gatewayhostnameconfiguration.NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue") + +// alternatively `client.ListByService(ctx, id, gatewayhostnameconfiguration.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, gatewayhostnameconfiguration.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/client.go b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/client.go new file mode 100644 index 00000000000..caf1c71d205 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/client.go @@ -0,0 +1,26 @@ +package gatewayhostnameconfiguration + +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 GatewayHostnameConfigurationClient struct { + Client *resourcemanager.Client +} + +func NewGatewayHostnameConfigurationClientWithBaseURI(sdkApi sdkEnv.Api) (*GatewayHostnameConfigurationClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "gatewayhostnameconfiguration", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GatewayHostnameConfigurationClient: %+v", err) + } + + return &GatewayHostnameConfigurationClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/id_hostnameconfiguration.go b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/id_hostnameconfiguration.go new file mode 100644 index 00000000000..510bff297ac --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/id_hostnameconfiguration.go @@ -0,0 +1,148 @@ +package gatewayhostnameconfiguration + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&HostnameConfigurationId{}) +} + +var _ resourceids.ResourceId = &HostnameConfigurationId{} + +// HostnameConfigurationId is a struct representing the Resource ID for a Hostname Configuration +type HostnameConfigurationId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + GatewayId string + HcId string +} + +// NewHostnameConfigurationID returns a new HostnameConfigurationId struct +func NewHostnameConfigurationID(subscriptionId string, resourceGroupName string, serviceName string, gatewayId string, hcId string) HostnameConfigurationId { + return HostnameConfigurationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + GatewayId: gatewayId, + HcId: hcId, + } +} + +// ParseHostnameConfigurationID parses 'input' into a HostnameConfigurationId +func ParseHostnameConfigurationID(input string) (*HostnameConfigurationId, error) { + parser := resourceids.NewParserFromResourceIdType(&HostnameConfigurationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := HostnameConfigurationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseHostnameConfigurationIDInsensitively parses 'input' case-insensitively into a HostnameConfigurationId +// note: this method should only be used for API response data and not user input +func ParseHostnameConfigurationIDInsensitively(input string) (*HostnameConfigurationId, error) { + parser := resourceids.NewParserFromResourceIdType(&HostnameConfigurationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := HostnameConfigurationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *HostnameConfigurationId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.GatewayId, ok = input.Parsed["gatewayId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "gatewayId", input) + } + + if id.HcId, ok = input.Parsed["hcId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "hcId", input) + } + + return nil +} + +// ValidateHostnameConfigurationID checks that 'input' can be parsed as a Hostname Configuration ID +func ValidateHostnameConfigurationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseHostnameConfigurationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Hostname Configuration ID +func (id HostnameConfigurationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/gateways/%s/hostnameConfigurations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.GatewayId, id.HcId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Hostname Configuration ID +func (id HostnameConfigurationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticGateways", "gateways", "gateways"), + resourceids.UserSpecifiedSegment("gatewayId", "gatewayIdValue"), + resourceids.StaticSegment("staticHostnameConfigurations", "hostnameConfigurations", "hostnameConfigurations"), + resourceids.UserSpecifiedSegment("hcId", "hcIdValue"), + } +} + +// String returns a human-readable description of this Hostname Configuration ID +func (id HostnameConfigurationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Gateway: %q", id.GatewayId), + fmt.Sprintf("Hc: %q", id.HcId), + } + return fmt.Sprintf("Hostname Configuration (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/id_hostnameconfiguration_test.go b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/id_hostnameconfiguration_test.go new file mode 100644 index 00000000000..cc55f04a67f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/id_hostnameconfiguration_test.go @@ -0,0 +1,372 @@ +package gatewayhostnameconfiguration + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &HostnameConfigurationId{} + +func TestNewHostnameConfigurationID(t *testing.T) { + id := NewHostnameConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue", "hcIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.GatewayId != "gatewayIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'GatewayId'", id.GatewayId, "gatewayIdValue") + } + + if id.HcId != "hcIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'HcId'", id.HcId, "hcIdValue") + } +} + +func TestFormatHostnameConfigurationID(t *testing.T) { + actual := NewHostnameConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue", "hcIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/hostnameConfigurations/hcIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseHostnameConfigurationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostnameConfigurationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/hostnameConfigurations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/hostnameConfigurations/hcIdValue", + Expected: &HostnameConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + HcId: "hcIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/hostnameConfigurations/hcIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostnameConfigurationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + if actual.HcId != v.Expected.HcId { + t.Fatalf("Expected %q but got %q for HcId", v.Expected.HcId, actual.HcId) + } + + } +} + +func TestParseHostnameConfigurationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HostnameConfigurationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/hostnameConfigurations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE/hOsTnAmEcOnFiGuRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/hostnameConfigurations/hcIdValue", + Expected: &HostnameConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + HcId: "hcIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/hostnameConfigurations/hcIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE/hOsTnAmEcOnFiGuRaTiOnS/hCiDvAlUe", + Expected: &HostnameConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + GatewayId: "gAtEwAyIdVaLuE", + HcId: "hCiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE/hOsTnAmEcOnFiGuRaTiOnS/hCiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHostnameConfigurationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + if actual.HcId != v.Expected.HcId { + t.Fatalf("Expected %q but got %q for HcId", v.Expected.HcId, actual.HcId) + } + + } +} + +func TestSegmentsForHostnameConfigurationId(t *testing.T) { + segments := HostnameConfigurationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("HostnameConfigurationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/id_servicegateway.go b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/id_servicegateway.go new file mode 100644 index 00000000000..70674a273b9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/id_servicegateway.go @@ -0,0 +1,139 @@ +package gatewayhostnameconfiguration + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceGatewayId{}) +} + +var _ resourceids.ResourceId = &ServiceGatewayId{} + +// ServiceGatewayId is a struct representing the Resource ID for a Service Gateway +type ServiceGatewayId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + GatewayId string +} + +// NewServiceGatewayID returns a new ServiceGatewayId struct +func NewServiceGatewayID(subscriptionId string, resourceGroupName string, serviceName string, gatewayId string) ServiceGatewayId { + return ServiceGatewayId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + GatewayId: gatewayId, + } +} + +// ParseServiceGatewayID parses 'input' into a ServiceGatewayId +func ParseServiceGatewayID(input string) (*ServiceGatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceGatewayId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceGatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceGatewayIDInsensitively parses 'input' case-insensitively into a ServiceGatewayId +// note: this method should only be used for API response data and not user input +func ParseServiceGatewayIDInsensitively(input string) (*ServiceGatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceGatewayId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceGatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceGatewayId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.GatewayId, ok = input.Parsed["gatewayId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "gatewayId", input) + } + + return nil +} + +// ValidateServiceGatewayID checks that 'input' can be parsed as a Service Gateway ID +func ValidateServiceGatewayID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceGatewayID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service Gateway ID +func (id ServiceGatewayId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/gateways/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.GatewayId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service Gateway ID +func (id ServiceGatewayId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticGateways", "gateways", "gateways"), + resourceids.UserSpecifiedSegment("gatewayId", "gatewayIdValue"), + } +} + +// String returns a human-readable description of this Service Gateway ID +func (id ServiceGatewayId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Gateway: %q", id.GatewayId), + } + return fmt.Sprintf("Service Gateway (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/id_servicegateway_test.go b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/id_servicegateway_test.go new file mode 100644 index 00000000000..2ff1d368e35 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/id_servicegateway_test.go @@ -0,0 +1,327 @@ +package gatewayhostnameconfiguration + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceGatewayId{} + +func TestNewServiceGatewayID(t *testing.T) { + id := NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.GatewayId != "gatewayIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'GatewayId'", id.GatewayId, "gatewayIdValue") + } +} + +func TestFormatServiceGatewayID(t *testing.T) { + actual := NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceGatewayID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceGatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceGatewayID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + } +} + +func TestParseServiceGatewayIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceGatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + GatewayId: "gAtEwAyIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceGatewayIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + } +} + +func TestSegmentsForServiceGatewayId(t *testing.T) { + segments := ServiceGatewayId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceGatewayId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/method_createorupdate.go new file mode 100644 index 00000000000..81fc99af124 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/method_createorupdate.go @@ -0,0 +1,88 @@ +package gatewayhostnameconfiguration + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GatewayHostnameConfigurationContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c GatewayHostnameConfigurationClient) CreateOrUpdate(ctx context.Context, id HostnameConfigurationId, input GatewayHostnameConfigurationContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 GatewayHostnameConfigurationContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/method_delete.go b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/method_delete.go new file mode 100644 index 00000000000..0964c8fdc78 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/method_delete.go @@ -0,0 +1,76 @@ +package gatewayhostnameconfiguration + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c GatewayHostnameConfigurationClient) Delete(ctx context.Context, id HostnameConfigurationId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/method_get.go b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/method_get.go new file mode 100644 index 00000000000..d04e4ef66d0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/method_get.go @@ -0,0 +1,54 @@ +package gatewayhostnameconfiguration + +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 *GatewayHostnameConfigurationContract +} + +// Get ... +func (c GatewayHostnameConfigurationClient) Get(ctx context.Context, id HostnameConfigurationId) (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 GatewayHostnameConfigurationContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/method_getentitytag.go new file mode 100644 index 00000000000..76b08b4e076 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/method_getentitytag.go @@ -0,0 +1,46 @@ +package gatewayhostnameconfiguration + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c GatewayHostnameConfigurationClient) GetEntityTag(ctx context.Context, id HostnameConfigurationId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/method_listbyservice.go new file mode 100644 index 00000000000..f34fd4bdb80 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/method_listbyservice.go @@ -0,0 +1,141 @@ +package gatewayhostnameconfiguration + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GatewayHostnameConfigurationContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []GatewayHostnameConfigurationContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c GatewayHostnameConfigurationClient) ListByService(ctx context.Context, id ServiceGatewayId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/hostnameConfigurations", 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 *[]GatewayHostnameConfigurationContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c GatewayHostnameConfigurationClient) ListByServiceComplete(ctx context.Context, id ServiceGatewayId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, GatewayHostnameConfigurationContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c GatewayHostnameConfigurationClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceGatewayId, options ListByServiceOperationOptions, predicate GatewayHostnameConfigurationContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]GatewayHostnameConfigurationContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/model_gatewayhostnameconfigurationcontract.go b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/model_gatewayhostnameconfigurationcontract.go new file mode 100644 index 00000000000..12edab4f738 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/model_gatewayhostnameconfigurationcontract.go @@ -0,0 +1,11 @@ +package gatewayhostnameconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewayHostnameConfigurationContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *GatewayHostnameConfigurationContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/model_gatewayhostnameconfigurationcontractproperties.go b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/model_gatewayhostnameconfigurationcontractproperties.go new file mode 100644 index 00000000000..b65ba16ec44 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/model_gatewayhostnameconfigurationcontractproperties.go @@ -0,0 +1,13 @@ +package gatewayhostnameconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewayHostnameConfigurationContractProperties struct { + CertificateId *string `json:"certificateId,omitempty"` + HTTP2Enabled *bool `json:"http2Enabled,omitempty"` + Hostname *string `json:"hostname,omitempty"` + NegotiateClientCertificate *bool `json:"negotiateClientCertificate,omitempty"` + Tls10Enabled *bool `json:"tls10Enabled,omitempty"` + Tls11Enabled *bool `json:"tls11Enabled,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/predicates.go b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/predicates.go new file mode 100644 index 00000000000..737fbb773b4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/predicates.go @@ -0,0 +1,27 @@ +package gatewayhostnameconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewayHostnameConfigurationContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p GatewayHostnameConfigurationContractOperationPredicate) Matches(input GatewayHostnameConfigurationContract) 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/apimanagement/2024-05-01/gatewayhostnameconfiguration/version.go b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/version.go new file mode 100644 index 00000000000..3d98f418796 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayhostnameconfiguration/version.go @@ -0,0 +1,12 @@ +package gatewayhostnameconfiguration + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/gatewayhostnameconfiguration/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayinvalidatedebugcredentials/client.go b/resource-manager/apimanagement/2024-05-01/gatewayinvalidatedebugcredentials/client.go new file mode 100644 index 00000000000..4c95799c9a3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayinvalidatedebugcredentials/client.go @@ -0,0 +1,26 @@ +package gatewayinvalidatedebugcredentials + +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 GatewayInvalidateDebugCredentialsClient struct { + Client *resourcemanager.Client +} + +func NewGatewayInvalidateDebugCredentialsClientWithBaseURI(sdkApi sdkEnv.Api) (*GatewayInvalidateDebugCredentialsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "gatewayinvalidatedebugcredentials", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GatewayInvalidateDebugCredentialsClient: %+v", err) + } + + return &GatewayInvalidateDebugCredentialsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayinvalidatedebugcredentials/id_servicegateway.go b/resource-manager/apimanagement/2024-05-01/gatewayinvalidatedebugcredentials/id_servicegateway.go new file mode 100644 index 00000000000..9f849ffe103 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayinvalidatedebugcredentials/id_servicegateway.go @@ -0,0 +1,139 @@ +package gatewayinvalidatedebugcredentials + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceGatewayId{}) +} + +var _ resourceids.ResourceId = &ServiceGatewayId{} + +// ServiceGatewayId is a struct representing the Resource ID for a Service Gateway +type ServiceGatewayId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + GatewayId string +} + +// NewServiceGatewayID returns a new ServiceGatewayId struct +func NewServiceGatewayID(subscriptionId string, resourceGroupName string, serviceName string, gatewayId string) ServiceGatewayId { + return ServiceGatewayId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + GatewayId: gatewayId, + } +} + +// ParseServiceGatewayID parses 'input' into a ServiceGatewayId +func ParseServiceGatewayID(input string) (*ServiceGatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceGatewayId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceGatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceGatewayIDInsensitively parses 'input' case-insensitively into a ServiceGatewayId +// note: this method should only be used for API response data and not user input +func ParseServiceGatewayIDInsensitively(input string) (*ServiceGatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceGatewayId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceGatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceGatewayId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.GatewayId, ok = input.Parsed["gatewayId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "gatewayId", input) + } + + return nil +} + +// ValidateServiceGatewayID checks that 'input' can be parsed as a Service Gateway ID +func ValidateServiceGatewayID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceGatewayID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service Gateway ID +func (id ServiceGatewayId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/gateways/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.GatewayId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service Gateway ID +func (id ServiceGatewayId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticGateways", "gateways", "gateways"), + resourceids.UserSpecifiedSegment("gatewayId", "gatewayIdValue"), + } +} + +// String returns a human-readable description of this Service Gateway ID +func (id ServiceGatewayId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Gateway: %q", id.GatewayId), + } + return fmt.Sprintf("Service Gateway (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayinvalidatedebugcredentials/id_servicegateway_test.go b/resource-manager/apimanagement/2024-05-01/gatewayinvalidatedebugcredentials/id_servicegateway_test.go new file mode 100644 index 00000000000..f2e167053cc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayinvalidatedebugcredentials/id_servicegateway_test.go @@ -0,0 +1,327 @@ +package gatewayinvalidatedebugcredentials + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceGatewayId{} + +func TestNewServiceGatewayID(t *testing.T) { + id := NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.GatewayId != "gatewayIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'GatewayId'", id.GatewayId, "gatewayIdValue") + } +} + +func TestFormatServiceGatewayID(t *testing.T) { + actual := NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceGatewayID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceGatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceGatewayID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + } +} + +func TestParseServiceGatewayIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceGatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + GatewayId: "gAtEwAyIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceGatewayIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + } +} + +func TestSegmentsForServiceGatewayId(t *testing.T) { + segments := ServiceGatewayId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceGatewayId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayinvalidatedebugcredentials/method_gatewayinvalidatedebugcredentials.go b/resource-manager/apimanagement/2024-05-01/gatewayinvalidatedebugcredentials/method_gatewayinvalidatedebugcredentials.go new file mode 100644 index 00000000000..cd8f0775e38 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayinvalidatedebugcredentials/method_gatewayinvalidatedebugcredentials.go @@ -0,0 +1,47 @@ +package gatewayinvalidatedebugcredentials + +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 GatewayInvalidateDebugCredentialsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GatewayInvalidateDebugCredentials ... +func (c GatewayInvalidateDebugCredentialsClient) GatewayInvalidateDebugCredentials(ctx context.Context, id ServiceGatewayId) (result GatewayInvalidateDebugCredentialsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/invalidateDebugCredentials", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayinvalidatedebugcredentials/version.go b/resource-manager/apimanagement/2024-05-01/gatewayinvalidatedebugcredentials/version.go new file mode 100644 index 00000000000..8adec08dbee --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayinvalidatedebugcredentials/version.go @@ -0,0 +1,12 @@ +package gatewayinvalidatedebugcredentials + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/gatewayinvalidatedebugcredentials/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/README.md b/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/README.md new file mode 100644 index 00000000000..5c7e1cc5a66 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/README.md @@ -0,0 +1,41 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials` Documentation + +The `gatewaylistdebugcredentials` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials" +``` + + +### Client Initialization + +```go +client := gatewaylistdebugcredentials.NewGatewayListDebugCredentialsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GatewayListDebugCredentialsClient.GatewayListDebugCredentials` + +```go +ctx := context.TODO() +id := gatewaylistdebugcredentials.NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue") + +payload := gatewaylistdebugcredentials.GatewayListDebugCredentialsContract{ + // ... +} + + +read, err := client.GatewayListDebugCredentials(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/apimanagement/2024-05-01/gatewaylistdebugcredentials/client.go b/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/client.go new file mode 100644 index 00000000000..6c497072ede --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/client.go @@ -0,0 +1,26 @@ +package gatewaylistdebugcredentials + +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 GatewayListDebugCredentialsClient struct { + Client *resourcemanager.Client +} + +func NewGatewayListDebugCredentialsClientWithBaseURI(sdkApi sdkEnv.Api) (*GatewayListDebugCredentialsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "gatewaylistdebugcredentials", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GatewayListDebugCredentialsClient: %+v", err) + } + + return &GatewayListDebugCredentialsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/constants.go b/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/constants.go new file mode 100644 index 00000000000..1d5689ac52a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/constants.go @@ -0,0 +1,48 @@ +package gatewaylistdebugcredentials + +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 GatewayListDebugCredentialsContractPurpose string + +const ( + GatewayListDebugCredentialsContractPurposeTracing GatewayListDebugCredentialsContractPurpose = "tracing" +) + +func PossibleValuesForGatewayListDebugCredentialsContractPurpose() []string { + return []string{ + string(GatewayListDebugCredentialsContractPurposeTracing), + } +} + +func (s *GatewayListDebugCredentialsContractPurpose) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGatewayListDebugCredentialsContractPurpose(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseGatewayListDebugCredentialsContractPurpose(input string) (*GatewayListDebugCredentialsContractPurpose, error) { + vals := map[string]GatewayListDebugCredentialsContractPurpose{ + "tracing": GatewayListDebugCredentialsContractPurposeTracing, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := GatewayListDebugCredentialsContractPurpose(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/id_servicegateway.go b/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/id_servicegateway.go new file mode 100644 index 00000000000..c219af55c3b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/id_servicegateway.go @@ -0,0 +1,139 @@ +package gatewaylistdebugcredentials + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceGatewayId{}) +} + +var _ resourceids.ResourceId = &ServiceGatewayId{} + +// ServiceGatewayId is a struct representing the Resource ID for a Service Gateway +type ServiceGatewayId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + GatewayId string +} + +// NewServiceGatewayID returns a new ServiceGatewayId struct +func NewServiceGatewayID(subscriptionId string, resourceGroupName string, serviceName string, gatewayId string) ServiceGatewayId { + return ServiceGatewayId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + GatewayId: gatewayId, + } +} + +// ParseServiceGatewayID parses 'input' into a ServiceGatewayId +func ParseServiceGatewayID(input string) (*ServiceGatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceGatewayId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceGatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceGatewayIDInsensitively parses 'input' case-insensitively into a ServiceGatewayId +// note: this method should only be used for API response data and not user input +func ParseServiceGatewayIDInsensitively(input string) (*ServiceGatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceGatewayId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceGatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceGatewayId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.GatewayId, ok = input.Parsed["gatewayId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "gatewayId", input) + } + + return nil +} + +// ValidateServiceGatewayID checks that 'input' can be parsed as a Service Gateway ID +func ValidateServiceGatewayID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceGatewayID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service Gateway ID +func (id ServiceGatewayId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/gateways/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.GatewayId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service Gateway ID +func (id ServiceGatewayId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticGateways", "gateways", "gateways"), + resourceids.UserSpecifiedSegment("gatewayId", "gatewayIdValue"), + } +} + +// String returns a human-readable description of this Service Gateway ID +func (id ServiceGatewayId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Gateway: %q", id.GatewayId), + } + return fmt.Sprintf("Service Gateway (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/id_servicegateway_test.go b/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/id_servicegateway_test.go new file mode 100644 index 00000000000..040339b7503 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/id_servicegateway_test.go @@ -0,0 +1,327 @@ +package gatewaylistdebugcredentials + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceGatewayId{} + +func TestNewServiceGatewayID(t *testing.T) { + id := NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.GatewayId != "gatewayIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'GatewayId'", id.GatewayId, "gatewayIdValue") + } +} + +func TestFormatServiceGatewayID(t *testing.T) { + actual := NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceGatewayID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceGatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceGatewayID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + } +} + +func TestParseServiceGatewayIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceGatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + GatewayId: "gAtEwAyIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceGatewayIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + } +} + +func TestSegmentsForServiceGatewayId(t *testing.T) { + segments := ServiceGatewayId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceGatewayId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/method_gatewaylistdebugcredentials.go b/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/method_gatewaylistdebugcredentials.go new file mode 100644 index 00000000000..322d77c35a2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/method_gatewaylistdebugcredentials.go @@ -0,0 +1,59 @@ +package gatewaylistdebugcredentials + +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 GatewayListDebugCredentialsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GatewayDebugCredentialsContract +} + +// GatewayListDebugCredentials ... +func (c GatewayListDebugCredentialsClient) GatewayListDebugCredentials(ctx context.Context, id ServiceGatewayId, input GatewayListDebugCredentialsContract) (result GatewayListDebugCredentialsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listDebugCredentials", 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 GatewayDebugCredentialsContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/model_gatewaydebugcredentialscontract.go b/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/model_gatewaydebugcredentialscontract.go new file mode 100644 index 00000000000..08517d8d0fc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/model_gatewaydebugcredentialscontract.go @@ -0,0 +1,8 @@ +package gatewaylistdebugcredentials + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewayDebugCredentialsContract struct { + Token *string `json:"token,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/model_gatewaylistdebugcredentialscontract.go b/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/model_gatewaylistdebugcredentialscontract.go new file mode 100644 index 00000000000..b5bfa66c653 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/model_gatewaylistdebugcredentialscontract.go @@ -0,0 +1,10 @@ +package gatewaylistdebugcredentials + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewayListDebugCredentialsContract struct { + ApiId string `json:"apiId"` + CredentialsExpireAfter *string `json:"credentialsExpireAfter,omitempty"` + Purposes []GatewayListDebugCredentialsContractPurpose `json:"purposes"` +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/version.go b/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/version.go new file mode 100644 index 00000000000..15a76021429 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaylistdebugcredentials/version.go @@ -0,0 +1,12 @@ +package gatewaylistdebugcredentials + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/gatewaylistdebugcredentials/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaylistkeys/README.md b/resource-manager/apimanagement/2024-05-01/gatewaylistkeys/README.md new file mode 100644 index 00000000000..5200403a454 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaylistkeys/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewaylistkeys` Documentation + +The `gatewaylistkeys` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewaylistkeys" +``` + + +### Client Initialization + +```go +client := gatewaylistkeys.NewGatewayListKeysClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GatewayListKeysClient.GatewayListKeys` + +```go +ctx := context.TODO() +id := gatewaylistkeys.NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue") + +read, err := client.GatewayListKeys(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/apimanagement/2024-05-01/gatewaylistkeys/client.go b/resource-manager/apimanagement/2024-05-01/gatewaylistkeys/client.go new file mode 100644 index 00000000000..a9b08e9562a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaylistkeys/client.go @@ -0,0 +1,26 @@ +package gatewaylistkeys + +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 GatewayListKeysClient struct { + Client *resourcemanager.Client +} + +func NewGatewayListKeysClientWithBaseURI(sdkApi sdkEnv.Api) (*GatewayListKeysClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "gatewaylistkeys", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GatewayListKeysClient: %+v", err) + } + + return &GatewayListKeysClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaylistkeys/id_servicegateway.go b/resource-manager/apimanagement/2024-05-01/gatewaylistkeys/id_servicegateway.go new file mode 100644 index 00000000000..eacc5d94b71 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaylistkeys/id_servicegateway.go @@ -0,0 +1,139 @@ +package gatewaylistkeys + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceGatewayId{}) +} + +var _ resourceids.ResourceId = &ServiceGatewayId{} + +// ServiceGatewayId is a struct representing the Resource ID for a Service Gateway +type ServiceGatewayId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + GatewayId string +} + +// NewServiceGatewayID returns a new ServiceGatewayId struct +func NewServiceGatewayID(subscriptionId string, resourceGroupName string, serviceName string, gatewayId string) ServiceGatewayId { + return ServiceGatewayId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + GatewayId: gatewayId, + } +} + +// ParseServiceGatewayID parses 'input' into a ServiceGatewayId +func ParseServiceGatewayID(input string) (*ServiceGatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceGatewayId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceGatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceGatewayIDInsensitively parses 'input' case-insensitively into a ServiceGatewayId +// note: this method should only be used for API response data and not user input +func ParseServiceGatewayIDInsensitively(input string) (*ServiceGatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceGatewayId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceGatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceGatewayId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.GatewayId, ok = input.Parsed["gatewayId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "gatewayId", input) + } + + return nil +} + +// ValidateServiceGatewayID checks that 'input' can be parsed as a Service Gateway ID +func ValidateServiceGatewayID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceGatewayID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service Gateway ID +func (id ServiceGatewayId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/gateways/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.GatewayId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service Gateway ID +func (id ServiceGatewayId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticGateways", "gateways", "gateways"), + resourceids.UserSpecifiedSegment("gatewayId", "gatewayIdValue"), + } +} + +// String returns a human-readable description of this Service Gateway ID +func (id ServiceGatewayId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Gateway: %q", id.GatewayId), + } + return fmt.Sprintf("Service Gateway (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaylistkeys/id_servicegateway_test.go b/resource-manager/apimanagement/2024-05-01/gatewaylistkeys/id_servicegateway_test.go new file mode 100644 index 00000000000..46f9400f7d6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaylistkeys/id_servicegateway_test.go @@ -0,0 +1,327 @@ +package gatewaylistkeys + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceGatewayId{} + +func TestNewServiceGatewayID(t *testing.T) { + id := NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.GatewayId != "gatewayIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'GatewayId'", id.GatewayId, "gatewayIdValue") + } +} + +func TestFormatServiceGatewayID(t *testing.T) { + actual := NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceGatewayID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceGatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceGatewayID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + } +} + +func TestParseServiceGatewayIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceGatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + GatewayId: "gAtEwAyIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceGatewayIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + } +} + +func TestSegmentsForServiceGatewayId(t *testing.T) { + segments := ServiceGatewayId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceGatewayId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaylistkeys/method_gatewaylistkeys.go b/resource-manager/apimanagement/2024-05-01/gatewaylistkeys/method_gatewaylistkeys.go new file mode 100644 index 00000000000..674953f6ad2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaylistkeys/method_gatewaylistkeys.go @@ -0,0 +1,55 @@ +package gatewaylistkeys + +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 GatewayListKeysOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GatewayKeysContract +} + +// GatewayListKeys ... +func (c GatewayListKeysClient) GatewayListKeys(ctx context.Context, id ServiceGatewayId) (result GatewayListKeysOperationResponse, 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 GatewayKeysContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaylistkeys/model_gatewaykeyscontract.go b/resource-manager/apimanagement/2024-05-01/gatewaylistkeys/model_gatewaykeyscontract.go new file mode 100644 index 00000000000..76109ac5547 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaylistkeys/model_gatewaykeyscontract.go @@ -0,0 +1,9 @@ +package gatewaylistkeys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewayKeysContract struct { + Primary *string `json:"primary,omitempty"` + Secondary *string `json:"secondary,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaylistkeys/version.go b/resource-manager/apimanagement/2024-05-01/gatewaylistkeys/version.go new file mode 100644 index 00000000000..4b454725d93 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaylistkeys/version.go @@ -0,0 +1,12 @@ +package gatewaylistkeys + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/gatewaylistkeys/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaylisttrace/README.md b/resource-manager/apimanagement/2024-05-01/gatewaylisttrace/README.md new file mode 100644 index 00000000000..f5a155ed279 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaylisttrace/README.md @@ -0,0 +1,41 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewaylisttrace` Documentation + +The `gatewaylisttrace` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewaylisttrace" +``` + + +### Client Initialization + +```go +client := gatewaylisttrace.NewGatewayListTraceClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GatewayListTraceClient.GatewayListTrace` + +```go +ctx := context.TODO() +id := gatewaylisttrace.NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue") + +payload := gatewaylisttrace.GatewayListTraceContract{ + // ... +} + + +read, err := client.GatewayListTrace(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/apimanagement/2024-05-01/gatewaylisttrace/client.go b/resource-manager/apimanagement/2024-05-01/gatewaylisttrace/client.go new file mode 100644 index 00000000000..f61a6ad2928 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaylisttrace/client.go @@ -0,0 +1,26 @@ +package gatewaylisttrace + +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 GatewayListTraceClient struct { + Client *resourcemanager.Client +} + +func NewGatewayListTraceClientWithBaseURI(sdkApi sdkEnv.Api) (*GatewayListTraceClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "gatewaylisttrace", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GatewayListTraceClient: %+v", err) + } + + return &GatewayListTraceClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaylisttrace/id_servicegateway.go b/resource-manager/apimanagement/2024-05-01/gatewaylisttrace/id_servicegateway.go new file mode 100644 index 00000000000..76d21bcd053 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaylisttrace/id_servicegateway.go @@ -0,0 +1,139 @@ +package gatewaylisttrace + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceGatewayId{}) +} + +var _ resourceids.ResourceId = &ServiceGatewayId{} + +// ServiceGatewayId is a struct representing the Resource ID for a Service Gateway +type ServiceGatewayId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + GatewayId string +} + +// NewServiceGatewayID returns a new ServiceGatewayId struct +func NewServiceGatewayID(subscriptionId string, resourceGroupName string, serviceName string, gatewayId string) ServiceGatewayId { + return ServiceGatewayId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + GatewayId: gatewayId, + } +} + +// ParseServiceGatewayID parses 'input' into a ServiceGatewayId +func ParseServiceGatewayID(input string) (*ServiceGatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceGatewayId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceGatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceGatewayIDInsensitively parses 'input' case-insensitively into a ServiceGatewayId +// note: this method should only be used for API response data and not user input +func ParseServiceGatewayIDInsensitively(input string) (*ServiceGatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceGatewayId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceGatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceGatewayId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.GatewayId, ok = input.Parsed["gatewayId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "gatewayId", input) + } + + return nil +} + +// ValidateServiceGatewayID checks that 'input' can be parsed as a Service Gateway ID +func ValidateServiceGatewayID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceGatewayID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service Gateway ID +func (id ServiceGatewayId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/gateways/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.GatewayId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service Gateway ID +func (id ServiceGatewayId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticGateways", "gateways", "gateways"), + resourceids.UserSpecifiedSegment("gatewayId", "gatewayIdValue"), + } +} + +// String returns a human-readable description of this Service Gateway ID +func (id ServiceGatewayId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Gateway: %q", id.GatewayId), + } + return fmt.Sprintf("Service Gateway (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaylisttrace/id_servicegateway_test.go b/resource-manager/apimanagement/2024-05-01/gatewaylisttrace/id_servicegateway_test.go new file mode 100644 index 00000000000..654eee83421 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaylisttrace/id_servicegateway_test.go @@ -0,0 +1,327 @@ +package gatewaylisttrace + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceGatewayId{} + +func TestNewServiceGatewayID(t *testing.T) { + id := NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.GatewayId != "gatewayIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'GatewayId'", id.GatewayId, "gatewayIdValue") + } +} + +func TestFormatServiceGatewayID(t *testing.T) { + actual := NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceGatewayID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceGatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceGatewayID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + } +} + +func TestParseServiceGatewayIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceGatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + GatewayId: "gAtEwAyIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceGatewayIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + } +} + +func TestSegmentsForServiceGatewayId(t *testing.T) { + segments := ServiceGatewayId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceGatewayId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaylisttrace/method_gatewaylisttrace.go b/resource-manager/apimanagement/2024-05-01/gatewaylisttrace/method_gatewaylisttrace.go new file mode 100644 index 00000000000..833a22a719e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaylisttrace/method_gatewaylisttrace.go @@ -0,0 +1,59 @@ +package gatewaylisttrace + +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 GatewayListTraceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *interface{} +} + +// GatewayListTrace ... +func (c GatewayListTraceClient) GatewayListTrace(ctx context.Context, id ServiceGatewayId, input GatewayListTraceContract) (result GatewayListTraceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listTrace", 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 interface{} + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaylisttrace/model_gatewaylisttracecontract.go b/resource-manager/apimanagement/2024-05-01/gatewaylisttrace/model_gatewaylisttracecontract.go new file mode 100644 index 00000000000..71f4f2def46 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaylisttrace/model_gatewaylisttracecontract.go @@ -0,0 +1,8 @@ +package gatewaylisttrace + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewayListTraceContract struct { + TraceId *string `json:"traceId,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewaylisttrace/version.go b/resource-manager/apimanagement/2024-05-01/gatewaylisttrace/version.go new file mode 100644 index 00000000000..5ffc17860dc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewaylisttrace/version.go @@ -0,0 +1,12 @@ +package gatewaylisttrace + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/gatewaylisttrace/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey/README.md b/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey/README.md new file mode 100644 index 00000000000..1db40ba9252 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey/README.md @@ -0,0 +1,41 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey` Documentation + +The `gatewayregeneratekey` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey" +``` + + +### Client Initialization + +```go +client := gatewayregeneratekey.NewGatewayRegenerateKeyClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GatewayRegenerateKeyClient.GatewayRegenerateKey` + +```go +ctx := context.TODO() +id := gatewayregeneratekey.NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue") + +payload := gatewayregeneratekey.GatewayKeyRegenerationRequestContract{ + // ... +} + + +read, err := client.GatewayRegenerateKey(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/apimanagement/2024-05-01/gatewayregeneratekey/client.go b/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey/client.go new file mode 100644 index 00000000000..aef06aab007 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey/client.go @@ -0,0 +1,26 @@ +package gatewayregeneratekey + +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 GatewayRegenerateKeyClient struct { + Client *resourcemanager.Client +} + +func NewGatewayRegenerateKeyClientWithBaseURI(sdkApi sdkEnv.Api) (*GatewayRegenerateKeyClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "gatewayregeneratekey", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GatewayRegenerateKeyClient: %+v", err) + } + + return &GatewayRegenerateKeyClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey/constants.go b/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey/constants.go new file mode 100644 index 00000000000..f8762636760 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey/constants.go @@ -0,0 +1,51 @@ +package gatewayregeneratekey + +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 KeyType string + +const ( + KeyTypePrimary KeyType = "primary" + KeyTypeSecondary KeyType = "secondary" +) + +func PossibleValuesForKeyType() []string { + return []string{ + string(KeyTypePrimary), + string(KeyTypeSecondary), + } +} + +func (s *KeyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKeyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseKeyType(input string) (*KeyType, error) { + vals := map[string]KeyType{ + "primary": KeyTypePrimary, + "secondary": KeyTypeSecondary, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := KeyType(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey/id_servicegateway.go b/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey/id_servicegateway.go new file mode 100644 index 00000000000..2df4b0f485a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey/id_servicegateway.go @@ -0,0 +1,139 @@ +package gatewayregeneratekey + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceGatewayId{}) +} + +var _ resourceids.ResourceId = &ServiceGatewayId{} + +// ServiceGatewayId is a struct representing the Resource ID for a Service Gateway +type ServiceGatewayId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + GatewayId string +} + +// NewServiceGatewayID returns a new ServiceGatewayId struct +func NewServiceGatewayID(subscriptionId string, resourceGroupName string, serviceName string, gatewayId string) ServiceGatewayId { + return ServiceGatewayId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + GatewayId: gatewayId, + } +} + +// ParseServiceGatewayID parses 'input' into a ServiceGatewayId +func ParseServiceGatewayID(input string) (*ServiceGatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceGatewayId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceGatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceGatewayIDInsensitively parses 'input' case-insensitively into a ServiceGatewayId +// note: this method should only be used for API response data and not user input +func ParseServiceGatewayIDInsensitively(input string) (*ServiceGatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceGatewayId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceGatewayId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceGatewayId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.GatewayId, ok = input.Parsed["gatewayId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "gatewayId", input) + } + + return nil +} + +// ValidateServiceGatewayID checks that 'input' can be parsed as a Service Gateway ID +func ValidateServiceGatewayID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceGatewayID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service Gateway ID +func (id ServiceGatewayId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/gateways/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.GatewayId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service Gateway ID +func (id ServiceGatewayId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticGateways", "gateways", "gateways"), + resourceids.UserSpecifiedSegment("gatewayId", "gatewayIdValue"), + } +} + +// String returns a human-readable description of this Service Gateway ID +func (id ServiceGatewayId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Gateway: %q", id.GatewayId), + } + return fmt.Sprintf("Service Gateway (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey/id_servicegateway_test.go b/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey/id_servicegateway_test.go new file mode 100644 index 00000000000..d20ee52aba1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey/id_servicegateway_test.go @@ -0,0 +1,327 @@ +package gatewayregeneratekey + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceGatewayId{} + +func TestNewServiceGatewayID(t *testing.T) { + id := NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.GatewayId != "gatewayIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'GatewayId'", id.GatewayId, "gatewayIdValue") + } +} + +func TestFormatServiceGatewayID(t *testing.T) { + actual := NewServiceGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "gatewayIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceGatewayID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceGatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceGatewayID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + } +} + +func TestParseServiceGatewayIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceGatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GatewayId: "gatewayIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/gateways/gatewayIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE", + Expected: &ServiceGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + GatewayId: "gAtEwAyIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gAtEwAyS/gAtEwAyIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceGatewayIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + } +} + +func TestSegmentsForServiceGatewayId(t *testing.T) { + segments := ServiceGatewayId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceGatewayId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey/method_gatewayregeneratekey.go b/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey/method_gatewayregeneratekey.go new file mode 100644 index 00000000000..c87c754f71a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey/method_gatewayregeneratekey.go @@ -0,0 +1,51 @@ +package gatewayregeneratekey + +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 GatewayRegenerateKeyOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GatewayRegenerateKey ... +func (c GatewayRegenerateKeyClient) GatewayRegenerateKey(ctx context.Context, id ServiceGatewayId, input GatewayKeyRegenerationRequestContract) (result GatewayRegenerateKeyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + 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 + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey/model_gatewaykeyregenerationrequestcontract.go b/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey/model_gatewaykeyregenerationrequestcontract.go new file mode 100644 index 00000000000..96f9ba1273d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey/model_gatewaykeyregenerationrequestcontract.go @@ -0,0 +1,8 @@ +package gatewayregeneratekey + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewayKeyRegenerationRequestContract struct { + KeyType KeyType `json:"keyType"` +} diff --git a/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey/version.go b/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey/version.go new file mode 100644 index 00000000000..4d4acb4a8b7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/gatewayregeneratekey/version.go @@ -0,0 +1,12 @@ +package gatewayregeneratekey + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/gatewayregeneratekey/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/README.md b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/README.md new file mode 100644 index 00000000000..74e968d3c9b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/README.md @@ -0,0 +1,127 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/graphqlapiresolver` Documentation + +The `graphqlapiresolver` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/graphqlapiresolver" +``` + + +### Client Initialization + +```go +client := graphqlapiresolver.NewGraphQLApiResolverClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GraphQLApiResolverClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := graphqlapiresolver.NewResolverID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "resolverIdValue") + +payload := graphqlapiresolver.ResolverContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, graphqlapiresolver.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GraphQLApiResolverClient.Delete` + +```go +ctx := context.TODO() +id := graphqlapiresolver.NewResolverID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "resolverIdValue") + +read, err := client.Delete(ctx, id, graphqlapiresolver.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GraphQLApiResolverClient.Get` + +```go +ctx := context.TODO() +id := graphqlapiresolver.NewResolverID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "resolverIdValue") + +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: `GraphQLApiResolverClient.GetEntityTag` + +```go +ctx := context.TODO() +id := graphqlapiresolver.NewResolverID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "resolverIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GraphQLApiResolverClient.ListByApi` + +```go +ctx := context.TODO() +id := graphqlapiresolver.NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + +// alternatively `client.ListByApi(ctx, id, graphqlapiresolver.DefaultListByApiOperationOptions())` can be used to do batched pagination +items, err := client.ListByApiComplete(ctx, id, graphqlapiresolver.DefaultListByApiOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `GraphQLApiResolverClient.Update` + +```go +ctx := context.TODO() +id := graphqlapiresolver.NewResolverID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "resolverIdValue") + +payload := graphqlapiresolver.ResolverUpdateContract{ + // ... +} + + +read, err := client.Update(ctx, id, payload, graphqlapiresolver.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/client.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/client.go new file mode 100644 index 00000000000..ae9f7510594 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/client.go @@ -0,0 +1,26 @@ +package graphqlapiresolver + +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 GraphQLApiResolverClient struct { + Client *resourcemanager.Client +} + +func NewGraphQLApiResolverClientWithBaseURI(sdkApi sdkEnv.Api) (*GraphQLApiResolverClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "graphqlapiresolver", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GraphQLApiResolverClient: %+v", err) + } + + return &GraphQLApiResolverClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/id_api.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/id_api.go new file mode 100644 index 00000000000..3f2483494f0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/id_api.go @@ -0,0 +1,139 @@ +package graphqlapiresolver + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiId{}) +} + +var _ resourceids.ResourceId = &ApiId{} + +// ApiId is a struct representing the Resource ID for a Api +type ApiId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string +} + +// NewApiID returns a new ApiId struct +func NewApiID(subscriptionId string, resourceGroupName string, serviceName string, apiId string) ApiId { + return ApiId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + } +} + +// ParseApiID parses 'input' into a ApiId +func ParseApiID(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiIDInsensitively parses 'input' case-insensitively into a ApiId +// note: this method should only be used for API response data and not user input +func ParseApiIDInsensitively(input string) (*ApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + return nil +} + +// ValidateApiID checks that 'input' can be parsed as a Api ID +func ValidateApiID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api ID +func (id ApiId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api ID +func (id ApiId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + } +} + +// String returns a human-readable description of this Api ID +func (id ApiId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + } + return fmt.Sprintf("Api (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/id_api_test.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/id_api_test.go new file mode 100644 index 00000000000..4246ff8ef2b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/id_api_test.go @@ -0,0 +1,327 @@ +package graphqlapiresolver + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiId{} + +func TestNewApiID(t *testing.T) { + id := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } +} + +func TestFormatApiID(t *testing.T) { + actual := NewApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestParseApiIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Expected: &ApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestSegmentsForApiId(t *testing.T) { + segments := ApiId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/id_resolver.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/id_resolver.go new file mode 100644 index 00000000000..3ff37f45676 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/id_resolver.go @@ -0,0 +1,148 @@ +package graphqlapiresolver + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ResolverId{}) +} + +var _ resourceids.ResourceId = &ResolverId{} + +// ResolverId is a struct representing the Resource ID for a Resolver +type ResolverId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string + ResolverId string +} + +// NewResolverID returns a new ResolverId struct +func NewResolverID(subscriptionId string, resourceGroupName string, serviceName string, apiId string, resolverId string) ResolverId { + return ResolverId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + ResolverId: resolverId, + } +} + +// ParseResolverID parses 'input' into a ResolverId +func ParseResolverID(input string) (*ResolverId, error) { + parser := resourceids.NewParserFromResourceIdType(&ResolverId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ResolverId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseResolverIDInsensitively parses 'input' case-insensitively into a ResolverId +// note: this method should only be used for API response data and not user input +func ParseResolverIDInsensitively(input string) (*ResolverId, error) { + parser := resourceids.NewParserFromResourceIdType(&ResolverId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ResolverId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ResolverId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + if id.ResolverId, ok = input.Parsed["resolverId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resolverId", input) + } + + return nil +} + +// ValidateResolverID checks that 'input' can be parsed as a Resolver ID +func ValidateResolverID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseResolverID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Resolver ID +func (id ResolverId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s/resolvers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId, id.ResolverId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Resolver ID +func (id ResolverId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + resourceids.StaticSegment("staticResolvers", "resolvers", "resolvers"), + resourceids.UserSpecifiedSegment("resolverId", "resolverIdValue"), + } +} + +// String returns a human-readable description of this Resolver ID +func (id ResolverId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + fmt.Sprintf("Resolver: %q", id.ResolverId), + } + return fmt.Sprintf("Resolver (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/id_resolver_test.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/id_resolver_test.go new file mode 100644 index 00000000000..1d33bf4e83a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/id_resolver_test.go @@ -0,0 +1,372 @@ +package graphqlapiresolver + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ResolverId{} + +func TestNewResolverID(t *testing.T) { + id := NewResolverID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "resolverIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } + + if id.ResolverId != "resolverIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ResolverId'", id.ResolverId, "resolverIdValue") + } +} + +func TestFormatResolverID(t *testing.T) { + actual := NewResolverID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "resolverIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/resolvers/resolverIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseResolverID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ResolverId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/resolvers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/resolvers/resolverIdValue", + Expected: &ResolverId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + ResolverId: "resolverIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/resolvers/resolverIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseResolverID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.ResolverId != v.Expected.ResolverId { + t.Fatalf("Expected %q but got %q for ResolverId", v.Expected.ResolverId, actual.ResolverId) + } + + } +} + +func TestParseResolverIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ResolverId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/resolvers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/rEsOlVeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/resolvers/resolverIdValue", + Expected: &ResolverId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + ResolverId: "resolverIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/resolvers/resolverIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/rEsOlVeRs/rEsOlVeRiDvAlUe", + Expected: &ResolverId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + ResolverId: "rEsOlVeRiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/rEsOlVeRs/rEsOlVeRiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseResolverIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.ResolverId != v.Expected.ResolverId { + t.Fatalf("Expected %q but got %q for ResolverId", v.Expected.ResolverId, actual.ResolverId) + } + + } +} + +func TestSegmentsForResolverId(t *testing.T) { + segments := ResolverId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ResolverId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/method_createorupdate.go new file mode 100644 index 00000000000..7860204fd3c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/method_createorupdate.go @@ -0,0 +1,88 @@ +package graphqlapiresolver + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ResolverContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c GraphQLApiResolverClient) CreateOrUpdate(ctx context.Context, id ResolverId, input ResolverContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 ResolverContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/method_delete.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/method_delete.go new file mode 100644 index 00000000000..914915dc4d6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/method_delete.go @@ -0,0 +1,76 @@ +package graphqlapiresolver + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c GraphQLApiResolverClient) Delete(ctx context.Context, id ResolverId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/method_get.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/method_get.go new file mode 100644 index 00000000000..8090c144df8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/method_get.go @@ -0,0 +1,54 @@ +package graphqlapiresolver + +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 *ResolverContract +} + +// Get ... +func (c GraphQLApiResolverClient) Get(ctx context.Context, id ResolverId) (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 ResolverContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/method_getentitytag.go new file mode 100644 index 00000000000..8b234a108a8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/method_getentitytag.go @@ -0,0 +1,46 @@ +package graphqlapiresolver + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c GraphQLApiResolverClient) GetEntityTag(ctx context.Context, id ResolverId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/method_listbyapi.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/method_listbyapi.go new file mode 100644 index 00000000000..5ce194fb6df --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/method_listbyapi.go @@ -0,0 +1,141 @@ +package graphqlapiresolver + +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 ListByApiOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ResolverContract +} + +type ListByApiCompleteResult struct { + LatestHttpResponse *http.Response + Items []ResolverContract +} + +type ListByApiOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByApiOperationOptions() ListByApiOperationOptions { + return ListByApiOperationOptions{} +} + +func (o ListByApiOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByApiOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByApiOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByApiCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByApiCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByApi ... +func (c GraphQLApiResolverClient) ListByApi(ctx context.Context, id ApiId, options ListByApiOperationOptions) (result ListByApiOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByApiCustomPager{}, + Path: fmt.Sprintf("%s/resolvers", 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 *[]ResolverContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByApiComplete retrieves all the results into a single object +func (c GraphQLApiResolverClient) ListByApiComplete(ctx context.Context, id ApiId, options ListByApiOperationOptions) (ListByApiCompleteResult, error) { + return c.ListByApiCompleteMatchingPredicate(ctx, id, options, ResolverContractOperationPredicate{}) +} + +// ListByApiCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c GraphQLApiResolverClient) ListByApiCompleteMatchingPredicate(ctx context.Context, id ApiId, options ListByApiOperationOptions, predicate ResolverContractOperationPredicate) (result ListByApiCompleteResult, err error) { + items := make([]ResolverContract, 0) + + resp, err := c.ListByApi(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByApiCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/method_update.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/method_update.go new file mode 100644 index 00000000000..3fa45e6fa93 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/method_update.go @@ -0,0 +1,87 @@ +package graphqlapiresolver + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ResolverContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c GraphQLApiResolverClient) Update(ctx context.Context, id ResolverId, input ResolverUpdateContract, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 ResolverContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/model_resolvercontract.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/model_resolvercontract.go new file mode 100644 index 00000000000..acca3ec7339 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/model_resolvercontract.go @@ -0,0 +1,11 @@ +package graphqlapiresolver + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResolverContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ResolverEntityBaseContract `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/model_resolverentitybasecontract.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/model_resolverentitybasecontract.go new file mode 100644 index 00000000000..8bff85524df --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/model_resolverentitybasecontract.go @@ -0,0 +1,10 @@ +package graphqlapiresolver + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResolverEntityBaseContract struct { + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + Path *string `json:"path,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/model_resolverupdatecontract.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/model_resolverupdatecontract.go new file mode 100644 index 00000000000..2f49480a7f9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/model_resolverupdatecontract.go @@ -0,0 +1,8 @@ +package graphqlapiresolver + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResolverUpdateContract struct { + Properties *ResolverUpdateContractProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/model_resolverupdatecontractproperties.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/model_resolverupdatecontractproperties.go new file mode 100644 index 00000000000..acd89e27f7b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/model_resolverupdatecontractproperties.go @@ -0,0 +1,10 @@ +package graphqlapiresolver + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResolverUpdateContractProperties struct { + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + Path *string `json:"path,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/predicates.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/predicates.go new file mode 100644 index 00000000000..2e2dabe5bd9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/predicates.go @@ -0,0 +1,27 @@ +package graphqlapiresolver + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResolverContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ResolverContractOperationPredicate) Matches(input ResolverContract) 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/apimanagement/2024-05-01/graphqlapiresolver/version.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/version.go new file mode 100644 index 00000000000..b2e30a5b87c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolver/version.go @@ -0,0 +1,12 @@ +package graphqlapiresolver + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/graphqlapiresolver/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/README.md b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/README.md new file mode 100644 index 00000000000..b24dda27ffb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/README.md @@ -0,0 +1,106 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy` Documentation + +The `graphqlapiresolverpolicy` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy" +``` + + +### Client Initialization + +```go +client := graphqlapiresolverpolicy.NewGraphQLApiResolverPolicyClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GraphQLApiResolverPolicyClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := graphqlapiresolverpolicy.NewResolverID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "resolverIdValue") + +payload := graphqlapiresolverpolicy.PolicyContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, graphqlapiresolverpolicy.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GraphQLApiResolverPolicyClient.Delete` + +```go +ctx := context.TODO() +id := graphqlapiresolverpolicy.NewResolverID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "resolverIdValue") + +read, err := client.Delete(ctx, id, graphqlapiresolverpolicy.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GraphQLApiResolverPolicyClient.Get` + +```go +ctx := context.TODO() +id := graphqlapiresolverpolicy.NewResolverID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "resolverIdValue") + +read, err := client.Get(ctx, id, graphqlapiresolverpolicy.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GraphQLApiResolverPolicyClient.GetEntityTag` + +```go +ctx := context.TODO() +id := graphqlapiresolverpolicy.NewResolverID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "resolverIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GraphQLApiResolverPolicyClient.ListByResolver` + +```go +ctx := context.TODO() +id := graphqlapiresolverpolicy.NewResolverID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "resolverIdValue") + +// alternatively `client.ListByResolver(ctx, id)` can be used to do batched pagination +items, err := client.ListByResolverComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/client.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/client.go new file mode 100644 index 00000000000..28db0b0bef5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/client.go @@ -0,0 +1,26 @@ +package graphqlapiresolverpolicy + +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 GraphQLApiResolverPolicyClient struct { + Client *resourcemanager.Client +} + +func NewGraphQLApiResolverPolicyClientWithBaseURI(sdkApi sdkEnv.Api) (*GraphQLApiResolverPolicyClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "graphqlapiresolverpolicy", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GraphQLApiResolverPolicyClient: %+v", err) + } + + return &GraphQLApiResolverPolicyClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/constants.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/constants.go new file mode 100644 index 00000000000..dac91618621 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/constants.go @@ -0,0 +1,98 @@ +package graphqlapiresolverpolicy + +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 PolicyContentFormat string + +const ( + PolicyContentFormatRawxml PolicyContentFormat = "rawxml" + PolicyContentFormatRawxmlNegativelink PolicyContentFormat = "rawxml-link" + PolicyContentFormatXml PolicyContentFormat = "xml" + PolicyContentFormatXmlNegativelink PolicyContentFormat = "xml-link" +) + +func PossibleValuesForPolicyContentFormat() []string { + return []string{ + string(PolicyContentFormatRawxml), + string(PolicyContentFormatRawxmlNegativelink), + string(PolicyContentFormatXml), + string(PolicyContentFormatXmlNegativelink), + } +} + +func (s *PolicyContentFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePolicyContentFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePolicyContentFormat(input string) (*PolicyContentFormat, error) { + vals := map[string]PolicyContentFormat{ + "rawxml": PolicyContentFormatRawxml, + "rawxml-link": PolicyContentFormatRawxmlNegativelink, + "xml": PolicyContentFormatXml, + "xml-link": PolicyContentFormatXmlNegativelink, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyContentFormat(input) + return &out, nil +} + +type PolicyExportFormat string + +const ( + PolicyExportFormatRawxml PolicyExportFormat = "rawxml" + PolicyExportFormatXml PolicyExportFormat = "xml" +) + +func PossibleValuesForPolicyExportFormat() []string { + return []string{ + string(PolicyExportFormatRawxml), + string(PolicyExportFormatXml), + } +} + +func (s *PolicyExportFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePolicyExportFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePolicyExportFormat(input string) (*PolicyExportFormat, error) { + vals := map[string]PolicyExportFormat{ + "rawxml": PolicyExportFormatRawxml, + "xml": PolicyExportFormatXml, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyExportFormat(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/id_resolver.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/id_resolver.go new file mode 100644 index 00000000000..84768e215d7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/id_resolver.go @@ -0,0 +1,148 @@ +package graphqlapiresolverpolicy + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ResolverId{}) +} + +var _ resourceids.ResourceId = &ResolverId{} + +// ResolverId is a struct representing the Resource ID for a Resolver +type ResolverId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ApiId string + ResolverId string +} + +// NewResolverID returns a new ResolverId struct +func NewResolverID(subscriptionId string, resourceGroupName string, serviceName string, apiId string, resolverId string) ResolverId { + return ResolverId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ApiId: apiId, + ResolverId: resolverId, + } +} + +// ParseResolverID parses 'input' into a ResolverId +func ParseResolverID(input string) (*ResolverId, error) { + parser := resourceids.NewParserFromResourceIdType(&ResolverId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ResolverId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseResolverIDInsensitively parses 'input' case-insensitively into a ResolverId +// note: this method should only be used for API response data and not user input +func ParseResolverIDInsensitively(input string) (*ResolverId, error) { + parser := resourceids.NewParserFromResourceIdType(&ResolverId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ResolverId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ResolverId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + if id.ResolverId, ok = input.Parsed["resolverId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resolverId", input) + } + + return nil +} + +// ValidateResolverID checks that 'input' can be parsed as a Resolver ID +func ValidateResolverID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseResolverID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Resolver ID +func (id ResolverId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/apis/%s/resolvers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId, id.ResolverId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Resolver ID +func (id ResolverId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + resourceids.StaticSegment("staticResolvers", "resolvers", "resolvers"), + resourceids.UserSpecifiedSegment("resolverId", "resolverIdValue"), + } +} + +// String returns a human-readable description of this Resolver ID +func (id ResolverId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Api: %q", id.ApiId), + fmt.Sprintf("Resolver: %q", id.ResolverId), + } + return fmt.Sprintf("Resolver (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/id_resolver_test.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/id_resolver_test.go new file mode 100644 index 00000000000..38a7d2cdfe7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/id_resolver_test.go @@ -0,0 +1,372 @@ +package graphqlapiresolverpolicy + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ResolverId{} + +func TestNewResolverID(t *testing.T) { + id := NewResolverID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "resolverIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } + + if id.ResolverId != "resolverIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ResolverId'", id.ResolverId, "resolverIdValue") + } +} + +func TestFormatResolverID(t *testing.T) { + actual := NewResolverID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "apiIdValue", "resolverIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/resolvers/resolverIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseResolverID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ResolverId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/resolvers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/resolvers/resolverIdValue", + Expected: &ResolverId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + ResolverId: "resolverIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/resolvers/resolverIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseResolverID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.ResolverId != v.Expected.ResolverId { + t.Fatalf("Expected %q but got %q for ResolverId", v.Expected.ResolverId, actual.ResolverId) + } + + } +} + +func TestParseResolverIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ResolverId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/resolvers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/rEsOlVeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/resolvers/resolverIdValue", + Expected: &ResolverId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ApiId: "apiIdValue", + ResolverId: "resolverIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue/resolvers/resolverIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/rEsOlVeRs/rEsOlVeRiDvAlUe", + Expected: &ResolverId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ApiId: "aPiIdVaLuE", + ResolverId: "rEsOlVeRiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/aPiS/aPiIdVaLuE/rEsOlVeRs/rEsOlVeRiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseResolverIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + if actual.ResolverId != v.Expected.ResolverId { + t.Fatalf("Expected %q but got %q for ResolverId", v.Expected.ResolverId, actual.ResolverId) + } + + } +} + +func TestSegmentsForResolverId(t *testing.T) { + segments := ResolverId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ResolverId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/method_createorupdate.go new file mode 100644 index 00000000000..c349e81087a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/method_createorupdate.go @@ -0,0 +1,88 @@ +package graphqlapiresolverpolicy + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c GraphQLApiResolverPolicyClient) CreateOrUpdate(ctx context.Context, id ResolverId, input PolicyContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", 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 PolicyContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/method_delete.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/method_delete.go new file mode 100644 index 00000000000..619ea1f6171 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/method_delete.go @@ -0,0 +1,76 @@ +package graphqlapiresolverpolicy + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c GraphQLApiResolverPolicyClient) Delete(ctx context.Context, id ResolverId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/method_get.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/method_get.go new file mode 100644 index 00000000000..4e49bd17793 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/method_get.go @@ -0,0 +1,83 @@ +package graphqlapiresolverpolicy + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyContract +} + +type GetOperationOptions struct { + Format *PolicyExportFormat +} + +func DefaultGetOperationOptions() GetOperationOptions { + return GetOperationOptions{} +} + +func (o GetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o GetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o GetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Format != nil { + out.Append("format", fmt.Sprintf("%v", *o.Format)) + } + return &out +} + +// Get ... +func (c GraphQLApiResolverPolicyClient) Get(ctx context.Context, id ResolverId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", 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 PolicyContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/method_getentitytag.go new file mode 100644 index 00000000000..74dcf82b122 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/method_getentitytag.go @@ -0,0 +1,47 @@ +package graphqlapiresolverpolicy + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c GraphQLApiResolverPolicyClient) GetEntityTag(ctx context.Context, id ResolverId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: fmt.Sprintf("%s/policies/policy", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/method_listbyresolver.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/method_listbyresolver.go new file mode 100644 index 00000000000..afed3381e23 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/method_listbyresolver.go @@ -0,0 +1,105 @@ +package graphqlapiresolverpolicy + +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 ListByResolverOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PolicyContract +} + +type ListByResolverCompleteResult struct { + LatestHttpResponse *http.Response + Items []PolicyContract +} + +type ListByResolverCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResolverCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResolver ... +func (c GraphQLApiResolverPolicyClient) ListByResolver(ctx context.Context, id ResolverId) (result ListByResolverOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByResolverCustomPager{}, + Path: fmt.Sprintf("%s/policies", 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 *[]PolicyContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResolverComplete retrieves all the results into a single object +func (c GraphQLApiResolverPolicyClient) ListByResolverComplete(ctx context.Context, id ResolverId) (ListByResolverCompleteResult, error) { + return c.ListByResolverCompleteMatchingPredicate(ctx, id, PolicyContractOperationPredicate{}) +} + +// ListByResolverCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c GraphQLApiResolverPolicyClient) ListByResolverCompleteMatchingPredicate(ctx context.Context, id ResolverId, predicate PolicyContractOperationPredicate) (result ListByResolverCompleteResult, err error) { + items := make([]PolicyContract, 0) + + resp, err := c.ListByResolver(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResolverCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/model_policycontract.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/model_policycontract.go new file mode 100644 index 00000000000..5d559ad25b0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/model_policycontract.go @@ -0,0 +1,11 @@ +package graphqlapiresolverpolicy + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PolicyContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/model_policycontractproperties.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/model_policycontractproperties.go new file mode 100644 index 00000000000..e6b9db4f618 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/model_policycontractproperties.go @@ -0,0 +1,9 @@ +package graphqlapiresolverpolicy + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyContractProperties struct { + Format *PolicyContentFormat `json:"format,omitempty"` + Value string `json:"value"` +} diff --git a/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/predicates.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/predicates.go new file mode 100644 index 00000000000..5da8b74603b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/predicates.go @@ -0,0 +1,27 @@ +package graphqlapiresolverpolicy + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PolicyContractOperationPredicate) Matches(input PolicyContract) 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/apimanagement/2024-05-01/graphqlapiresolverpolicy/version.go b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/version.go new file mode 100644 index 00000000000..7ec593546a1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/graphqlapiresolverpolicy/version.go @@ -0,0 +1,12 @@ +package graphqlapiresolverpolicy + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/graphqlapiresolverpolicy/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/group/README.md b/resource-manager/apimanagement/2024-05-01/group/README.md new file mode 100644 index 00000000000..f07c29b7cef --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/README.md @@ -0,0 +1,234 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/group` Documentation + +The `group` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/group" +``` + + +### Client Initialization + +```go +client := group.NewGroupClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GroupClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := group.NewGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "groupIdValue") + +payload := group.GroupCreateParameters{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, group.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GroupClient.Delete` + +```go +ctx := context.TODO() +id := group.NewGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "groupIdValue") + +read, err := client.Delete(ctx, id, group.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GroupClient.Get` + +```go +ctx := context.TODO() +id := group.NewGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "groupIdValue") + +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: `GroupClient.GetEntityTag` + +```go +ctx := context.TODO() +id := group.NewGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "groupIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GroupClient.ListByService` + +```go +ctx := context.TODO() +id := group.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, group.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, group.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `GroupClient.Update` + +```go +ctx := context.TODO() +id := group.NewGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "groupIdValue") + +payload := group.GroupUpdateParameters{ + // ... +} + + +read, err := client.Update(ctx, id, payload, group.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GroupClient.WorkspaceGroupCreateOrUpdate` + +```go +ctx := context.TODO() +id := group.NewWorkspaceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "groupIdValue") + +payload := group.GroupCreateParameters{ + // ... +} + + +read, err := client.WorkspaceGroupCreateOrUpdate(ctx, id, payload, group.DefaultWorkspaceGroupCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GroupClient.WorkspaceGroupDelete` + +```go +ctx := context.TODO() +id := group.NewWorkspaceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "groupIdValue") + +read, err := client.WorkspaceGroupDelete(ctx, id, group.DefaultWorkspaceGroupDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GroupClient.WorkspaceGroupGet` + +```go +ctx := context.TODO() +id := group.NewWorkspaceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "groupIdValue") + +read, err := client.WorkspaceGroupGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GroupClient.WorkspaceGroupGetEntityTag` + +```go +ctx := context.TODO() +id := group.NewWorkspaceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "groupIdValue") + +read, err := client.WorkspaceGroupGetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GroupClient.WorkspaceGroupListByService` + +```go +ctx := context.TODO() +id := group.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +// alternatively `client.WorkspaceGroupListByService(ctx, id, group.DefaultWorkspaceGroupListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.WorkspaceGroupListByServiceComplete(ctx, id, group.DefaultWorkspaceGroupListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `GroupClient.WorkspaceGroupUpdate` + +```go +ctx := context.TODO() +id := group.NewWorkspaceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "groupIdValue") + +payload := group.GroupUpdateParameters{ + // ... +} + + +read, err := client.WorkspaceGroupUpdate(ctx, id, payload, group.DefaultWorkspaceGroupUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/group/client.go b/resource-manager/apimanagement/2024-05-01/group/client.go new file mode 100644 index 00000000000..0301e35f4e8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/client.go @@ -0,0 +1,26 @@ +package group + +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 GroupClient struct { + Client *resourcemanager.Client +} + +func NewGroupClientWithBaseURI(sdkApi sdkEnv.Api) (*GroupClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "group", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GroupClient: %+v", err) + } + + return &GroupClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/group/constants.go b/resource-manager/apimanagement/2024-05-01/group/constants.go new file mode 100644 index 00000000000..1cda5dadcaf --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/constants.go @@ -0,0 +1,54 @@ +package group + +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 GroupType string + +const ( + GroupTypeCustom GroupType = "custom" + GroupTypeExternal GroupType = "external" + GroupTypeSystem GroupType = "system" +) + +func PossibleValuesForGroupType() []string { + return []string{ + string(GroupTypeCustom), + string(GroupTypeExternal), + string(GroupTypeSystem), + } +} + +func (s *GroupType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGroupType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseGroupType(input string) (*GroupType, error) { + vals := map[string]GroupType{ + "custom": GroupTypeCustom, + "external": GroupTypeExternal, + "system": GroupTypeSystem, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := GroupType(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/group/id_group.go b/resource-manager/apimanagement/2024-05-01/group/id_group.go new file mode 100644 index 00000000000..033b00db2ff --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/id_group.go @@ -0,0 +1,139 @@ +package group + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&GroupId{}) +} + +var _ resourceids.ResourceId = &GroupId{} + +// GroupId is a struct representing the Resource ID for a Group +type GroupId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + GroupId string +} + +// NewGroupID returns a new GroupId struct +func NewGroupID(subscriptionId string, resourceGroupName string, serviceName string, groupId string) GroupId { + return GroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + GroupId: groupId, + } +} + +// ParseGroupID parses 'input' into a GroupId +func ParseGroupID(input string) (*GroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&GroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GroupId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGroupIDInsensitively parses 'input' case-insensitively into a GroupId +// note: this method should only be used for API response data and not user input +func ParseGroupIDInsensitively(input string) (*GroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&GroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GroupId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GroupId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.GroupId, ok = input.Parsed["groupId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupId", input) + } + + return nil +} + +// ValidateGroupID checks that 'input' can be parsed as a Group ID +func ValidateGroupID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Group ID +func (id GroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/groups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.GroupId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Group ID +func (id GroupId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticGroups", "groups", "groups"), + resourceids.UserSpecifiedSegment("groupId", "groupIdValue"), + } +} + +// String returns a human-readable description of this Group ID +func (id GroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Group: %q", id.GroupId), + } + return fmt.Sprintf("Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/group/id_group_test.go b/resource-manager/apimanagement/2024-05-01/group/id_group_test.go new file mode 100644 index 00000000000..014c7cde759 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/id_group_test.go @@ -0,0 +1,327 @@ +package group + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GroupId{} + +func TestNewGroupID(t *testing.T) { + id := NewGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "groupIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.GroupId != "groupIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'GroupId'", id.GroupId, "groupIdValue") + } +} + +func TestFormatGroupID(t *testing.T) { + actual := NewGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "groupIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups/groupIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GroupId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups/groupIdValue", + Expected: &GroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GroupId: "groupIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups/groupIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGroupID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + } +} + +func TestParseGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GroupId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups/groupIdValue", + Expected: &GroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GroupId: "groupIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups/groupIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gRoUpS/gRoUpIdVaLuE", + Expected: &GroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + GroupId: "gRoUpIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gRoUpS/gRoUpIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGroupIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + } +} + +func TestSegmentsForGroupId(t *testing.T) { + segments := GroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GroupId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/group/id_service.go b/resource-manager/apimanagement/2024-05-01/group/id_service.go new file mode 100644 index 00000000000..b997cba49d0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/id_service.go @@ -0,0 +1,130 @@ +package group + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/group/id_service_test.go b/resource-manager/apimanagement/2024-05-01/group/id_service_test.go new file mode 100644 index 00000000000..22f68aaa970 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/id_service_test.go @@ -0,0 +1,282 @@ +package group + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/group/id_workspace.go b/resource-manager/apimanagement/2024-05-01/group/id_workspace.go new file mode 100644 index 00000000000..2a31e848c5a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/id_workspace.go @@ -0,0 +1,139 @@ +package group + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/group/id_workspace_test.go b/resource-manager/apimanagement/2024-05-01/group/id_workspace_test.go new file mode 100644 index 00000000000..d43b87bca14 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/id_workspace_test.go @@ -0,0 +1,327 @@ +package group + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/group/id_workspacegroup.go b/resource-manager/apimanagement/2024-05-01/group/id_workspacegroup.go new file mode 100644 index 00000000000..d95eae81434 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/id_workspacegroup.go @@ -0,0 +1,148 @@ +package group + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceGroupId{}) +} + +var _ resourceids.ResourceId = &WorkspaceGroupId{} + +// WorkspaceGroupId is a struct representing the Resource ID for a Workspace Group +type WorkspaceGroupId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + GroupId string +} + +// NewWorkspaceGroupID returns a new WorkspaceGroupId struct +func NewWorkspaceGroupID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, groupId string) WorkspaceGroupId { + return WorkspaceGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + GroupId: groupId, + } +} + +// ParseWorkspaceGroupID parses 'input' into a WorkspaceGroupId +func ParseWorkspaceGroupID(input string) (*WorkspaceGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceGroupId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceGroupIDInsensitively parses 'input' case-insensitively into a WorkspaceGroupId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceGroupIDInsensitively(input string) (*WorkspaceGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceGroupId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceGroupId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.GroupId, ok = input.Parsed["groupId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupId", input) + } + + return nil +} + +// ValidateWorkspaceGroupID checks that 'input' can be parsed as a Workspace Group ID +func ValidateWorkspaceGroupID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Group ID +func (id WorkspaceGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/groups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.GroupId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Group ID +func (id WorkspaceGroupId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticGroups", "groups", "groups"), + resourceids.UserSpecifiedSegment("groupId", "groupIdValue"), + } +} + +// String returns a human-readable description of this Workspace Group ID +func (id WorkspaceGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Group: %q", id.GroupId), + } + return fmt.Sprintf("Workspace Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/group/id_workspacegroup_test.go b/resource-manager/apimanagement/2024-05-01/group/id_workspacegroup_test.go new file mode 100644 index 00000000000..1c070056eb2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/id_workspacegroup_test.go @@ -0,0 +1,372 @@ +package group + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceGroupId{} + +func TestNewWorkspaceGroupID(t *testing.T) { + id := NewWorkspaceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "groupIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.GroupId != "groupIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'GroupId'", id.GroupId, "groupIdValue") + } +} + +func TestFormatWorkspaceGroupID(t *testing.T) { + actual := NewWorkspaceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "groupIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups/groupIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceGroupId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups/groupIdValue", + Expected: &WorkspaceGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + GroupId: "groupIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups/groupIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceGroupID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + } +} + +func TestParseWorkspaceGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceGroupId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/gRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups/groupIdValue", + Expected: &WorkspaceGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + GroupId: "groupIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups/groupIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/gRoUpS/gRoUpIdVaLuE", + Expected: &WorkspaceGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + GroupId: "gRoUpIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/gRoUpS/gRoUpIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceGroupIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + } +} + +func TestSegmentsForWorkspaceGroupId(t *testing.T) { + segments := WorkspaceGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceGroupId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/group/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/group/method_createorupdate.go new file mode 100644 index 00000000000..e8b639dbe8b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/method_createorupdate.go @@ -0,0 +1,88 @@ +package group + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GroupContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c GroupClient) CreateOrUpdate(ctx context.Context, id GroupId, input GroupCreateParameters, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 GroupContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/group/method_delete.go b/resource-manager/apimanagement/2024-05-01/group/method_delete.go new file mode 100644 index 00000000000..b7358fde533 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/method_delete.go @@ -0,0 +1,76 @@ +package group + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c GroupClient) Delete(ctx context.Context, id GroupId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/group/method_get.go b/resource-manager/apimanagement/2024-05-01/group/method_get.go new file mode 100644 index 00000000000..71da80e4425 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/method_get.go @@ -0,0 +1,54 @@ +package group + +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 *GroupContract +} + +// Get ... +func (c GroupClient) Get(ctx context.Context, id GroupId) (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 GroupContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/group/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/group/method_getentitytag.go new file mode 100644 index 00000000000..e6ee5a9ba2d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/method_getentitytag.go @@ -0,0 +1,46 @@ +package group + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c GroupClient) GetEntityTag(ctx context.Context, id GroupId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/group/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/group/method_listbyservice.go new file mode 100644 index 00000000000..4f8da96ef4a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/method_listbyservice.go @@ -0,0 +1,141 @@ +package group + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GroupContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []GroupContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c GroupClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/groups", 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 *[]GroupContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c GroupClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, GroupContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c GroupClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate GroupContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]GroupContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/group/method_update.go b/resource-manager/apimanagement/2024-05-01/group/method_update.go new file mode 100644 index 00000000000..70066730bb1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/method_update.go @@ -0,0 +1,87 @@ +package group + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GroupContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c GroupClient) Update(ctx context.Context, id GroupId, input GroupUpdateParameters, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 GroupContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/group/method_workspacegroupcreateorupdate.go b/resource-manager/apimanagement/2024-05-01/group/method_workspacegroupcreateorupdate.go new file mode 100644 index 00000000000..5ad40a08c47 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/method_workspacegroupcreateorupdate.go @@ -0,0 +1,88 @@ +package group + +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 WorkspaceGroupCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GroupContract +} + +type WorkspaceGroupCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceGroupCreateOrUpdateOperationOptions() WorkspaceGroupCreateOrUpdateOperationOptions { + return WorkspaceGroupCreateOrUpdateOperationOptions{} +} + +func (o WorkspaceGroupCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceGroupCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceGroupCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceGroupCreateOrUpdate ... +func (c GroupClient) WorkspaceGroupCreateOrUpdate(ctx context.Context, id WorkspaceGroupId, input GroupCreateParameters, options WorkspaceGroupCreateOrUpdateOperationOptions) (result WorkspaceGroupCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 GroupContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/group/method_workspacegroupdelete.go b/resource-manager/apimanagement/2024-05-01/group/method_workspacegroupdelete.go new file mode 100644 index 00000000000..949a8cb1846 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/method_workspacegroupdelete.go @@ -0,0 +1,76 @@ +package group + +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 WorkspaceGroupDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type WorkspaceGroupDeleteOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceGroupDeleteOperationOptions() WorkspaceGroupDeleteOperationOptions { + return WorkspaceGroupDeleteOperationOptions{} +} + +func (o WorkspaceGroupDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceGroupDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceGroupDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceGroupDelete ... +func (c GroupClient) WorkspaceGroupDelete(ctx context.Context, id WorkspaceGroupId, options WorkspaceGroupDeleteOperationOptions) (result WorkspaceGroupDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/group/method_workspacegroupget.go b/resource-manager/apimanagement/2024-05-01/group/method_workspacegroupget.go new file mode 100644 index 00000000000..88a4fa8e56b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/method_workspacegroupget.go @@ -0,0 +1,54 @@ +package group + +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 WorkspaceGroupGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GroupContract +} + +// WorkspaceGroupGet ... +func (c GroupClient) WorkspaceGroupGet(ctx context.Context, id WorkspaceGroupId) (result WorkspaceGroupGetOperationResponse, 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 GroupContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/group/method_workspacegroupgetentitytag.go b/resource-manager/apimanagement/2024-05-01/group/method_workspacegroupgetentitytag.go new file mode 100644 index 00000000000..6312fdc474c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/method_workspacegroupgetentitytag.go @@ -0,0 +1,46 @@ +package group + +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 WorkspaceGroupGetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceGroupGetEntityTag ... +func (c GroupClient) WorkspaceGroupGetEntityTag(ctx context.Context, id WorkspaceGroupId) (result WorkspaceGroupGetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/group/method_workspacegrouplistbyservice.go b/resource-manager/apimanagement/2024-05-01/group/method_workspacegrouplistbyservice.go new file mode 100644 index 00000000000..2aa11bf1959 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/method_workspacegrouplistbyservice.go @@ -0,0 +1,141 @@ +package group + +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 WorkspaceGroupListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GroupContract +} + +type WorkspaceGroupListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []GroupContract +} + +type WorkspaceGroupListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultWorkspaceGroupListByServiceOperationOptions() WorkspaceGroupListByServiceOperationOptions { + return WorkspaceGroupListByServiceOperationOptions{} +} + +func (o WorkspaceGroupListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceGroupListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceGroupListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspaceGroupListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceGroupListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceGroupListByService ... +func (c GroupClient) WorkspaceGroupListByService(ctx context.Context, id WorkspaceId, options WorkspaceGroupListByServiceOperationOptions) (result WorkspaceGroupListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspaceGroupListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/groups", 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 *[]GroupContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceGroupListByServiceComplete retrieves all the results into a single object +func (c GroupClient) WorkspaceGroupListByServiceComplete(ctx context.Context, id WorkspaceId, options WorkspaceGroupListByServiceOperationOptions) (WorkspaceGroupListByServiceCompleteResult, error) { + return c.WorkspaceGroupListByServiceCompleteMatchingPredicate(ctx, id, options, GroupContractOperationPredicate{}) +} + +// WorkspaceGroupListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c GroupClient) WorkspaceGroupListByServiceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options WorkspaceGroupListByServiceOperationOptions, predicate GroupContractOperationPredicate) (result WorkspaceGroupListByServiceCompleteResult, err error) { + items := make([]GroupContract, 0) + + resp, err := c.WorkspaceGroupListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceGroupListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/group/method_workspacegroupupdate.go b/resource-manager/apimanagement/2024-05-01/group/method_workspacegroupupdate.go new file mode 100644 index 00000000000..6e246635560 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/method_workspacegroupupdate.go @@ -0,0 +1,87 @@ +package group + +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 WorkspaceGroupUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GroupContract +} + +type WorkspaceGroupUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceGroupUpdateOperationOptions() WorkspaceGroupUpdateOperationOptions { + return WorkspaceGroupUpdateOperationOptions{} +} + +func (o WorkspaceGroupUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceGroupUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceGroupUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceGroupUpdate ... +func (c GroupClient) WorkspaceGroupUpdate(ctx context.Context, id WorkspaceGroupId, input GroupUpdateParameters, options WorkspaceGroupUpdateOperationOptions) (result WorkspaceGroupUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 GroupContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/group/model_groupcontract.go b/resource-manager/apimanagement/2024-05-01/group/model_groupcontract.go new file mode 100644 index 00000000000..fe07f849a1e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/model_groupcontract.go @@ -0,0 +1,11 @@ +package group + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *GroupContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/group/model_groupcontractproperties.go b/resource-manager/apimanagement/2024-05-01/group/model_groupcontractproperties.go new file mode 100644 index 00000000000..ed0d54f3d69 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/model_groupcontractproperties.go @@ -0,0 +1,12 @@ +package group + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupContractProperties struct { + BuiltIn *bool `json:"builtIn,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName string `json:"displayName"` + ExternalId *string `json:"externalId,omitempty"` + Type *GroupType `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/group/model_groupcreateparameters.go b/resource-manager/apimanagement/2024-05-01/group/model_groupcreateparameters.go new file mode 100644 index 00000000000..74c0d6cdd97 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/model_groupcreateparameters.go @@ -0,0 +1,8 @@ +package group + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupCreateParameters struct { + Properties *GroupCreateParametersProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/group/model_groupcreateparametersproperties.go b/resource-manager/apimanagement/2024-05-01/group/model_groupcreateparametersproperties.go new file mode 100644 index 00000000000..8cb28930b11 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/model_groupcreateparametersproperties.go @@ -0,0 +1,11 @@ +package group + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupCreateParametersProperties struct { + Description *string `json:"description,omitempty"` + DisplayName string `json:"displayName"` + ExternalId *string `json:"externalId,omitempty"` + Type *GroupType `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/group/model_groupupdateparameters.go b/resource-manager/apimanagement/2024-05-01/group/model_groupupdateparameters.go new file mode 100644 index 00000000000..e9ba5ed65cc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/model_groupupdateparameters.go @@ -0,0 +1,8 @@ +package group + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupUpdateParameters struct { + Properties *GroupUpdateParametersProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/group/model_groupupdateparametersproperties.go b/resource-manager/apimanagement/2024-05-01/group/model_groupupdateparametersproperties.go new file mode 100644 index 00000000000..c9a758948ce --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/model_groupupdateparametersproperties.go @@ -0,0 +1,11 @@ +package group + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupUpdateParametersProperties struct { + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + ExternalId *string `json:"externalId,omitempty"` + Type *GroupType `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/group/predicates.go b/resource-manager/apimanagement/2024-05-01/group/predicates.go new file mode 100644 index 00000000000..c6031629295 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/predicates.go @@ -0,0 +1,27 @@ +package group + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p GroupContractOperationPredicate) Matches(input GroupContract) 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/apimanagement/2024-05-01/group/version.go b/resource-manager/apimanagement/2024-05-01/group/version.go new file mode 100644 index 00000000000..3c0d54b6b3f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/group/version.go @@ -0,0 +1,12 @@ +package group + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/group/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/groupuser/README.md b/resource-manager/apimanagement/2024-05-01/groupuser/README.md new file mode 100644 index 00000000000..8a9e838ab2d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/README.md @@ -0,0 +1,150 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/groupuser` Documentation + +The `groupuser` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/groupuser" +``` + + +### Client Initialization + +```go +client := groupuser.NewGroupUserClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GroupUserClient.CheckEntityExists` + +```go +ctx := context.TODO() +id := groupuser.NewGroupUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "groupIdValue", "userIdValue") + +read, err := client.CheckEntityExists(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GroupUserClient.Create` + +```go +ctx := context.TODO() +id := groupuser.NewGroupUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "groupIdValue", "userIdValue") + +read, err := client.Create(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GroupUserClient.Delete` + +```go +ctx := context.TODO() +id := groupuser.NewGroupUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "groupIdValue", "userIdValue") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GroupUserClient.List` + +```go +ctx := context.TODO() +id := groupuser.NewGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "groupIdValue") + +// alternatively `client.List(ctx, id, groupuser.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, groupuser.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `GroupUserClient.WorkspaceGroupUserCheckEntityExists` + +```go +ctx := context.TODO() +id := groupuser.NewWorkspaceGroupUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "groupIdValue", "userIdValue") + +read, err := client.WorkspaceGroupUserCheckEntityExists(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GroupUserClient.WorkspaceGroupUserCreate` + +```go +ctx := context.TODO() +id := groupuser.NewWorkspaceGroupUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "groupIdValue", "userIdValue") + +read, err := client.WorkspaceGroupUserCreate(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GroupUserClient.WorkspaceGroupUserDelete` + +```go +ctx := context.TODO() +id := groupuser.NewWorkspaceGroupUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "groupIdValue", "userIdValue") + +read, err := client.WorkspaceGroupUserDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GroupUserClient.WorkspaceGroupUserList` + +```go +ctx := context.TODO() +id := groupuser.NewWorkspaceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "groupIdValue") + +// alternatively `client.WorkspaceGroupUserList(ctx, id, groupuser.DefaultWorkspaceGroupUserListOperationOptions())` can be used to do batched pagination +items, err := client.WorkspaceGroupUserListComplete(ctx, id, groupuser.DefaultWorkspaceGroupUserListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/groupuser/client.go b/resource-manager/apimanagement/2024-05-01/groupuser/client.go new file mode 100644 index 00000000000..7a2d9304c73 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/client.go @@ -0,0 +1,26 @@ +package groupuser + +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 GroupUserClient struct { + Client *resourcemanager.Client +} + +func NewGroupUserClientWithBaseURI(sdkApi sdkEnv.Api) (*GroupUserClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "groupuser", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GroupUserClient: %+v", err) + } + + return &GroupUserClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/groupuser/constants.go b/resource-manager/apimanagement/2024-05-01/groupuser/constants.go new file mode 100644 index 00000000000..520579fefd7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/constants.go @@ -0,0 +1,101 @@ +package groupuser + +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 GroupType string + +const ( + GroupTypeCustom GroupType = "custom" + GroupTypeExternal GroupType = "external" + GroupTypeSystem GroupType = "system" +) + +func PossibleValuesForGroupType() []string { + return []string{ + string(GroupTypeCustom), + string(GroupTypeExternal), + string(GroupTypeSystem), + } +} + +func (s *GroupType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGroupType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseGroupType(input string) (*GroupType, error) { + vals := map[string]GroupType{ + "custom": GroupTypeCustom, + "external": GroupTypeExternal, + "system": GroupTypeSystem, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := GroupType(input) + return &out, nil +} + +type UserState string + +const ( + UserStateActive UserState = "active" + UserStateBlocked UserState = "blocked" + UserStateDeleted UserState = "deleted" + UserStatePending UserState = "pending" +) + +func PossibleValuesForUserState() []string { + return []string{ + string(UserStateActive), + string(UserStateBlocked), + string(UserStateDeleted), + string(UserStatePending), + } +} + +func (s *UserState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUserState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseUserState(input string) (*UserState, error) { + vals := map[string]UserState{ + "active": UserStateActive, + "blocked": UserStateBlocked, + "deleted": UserStateDeleted, + "pending": UserStatePending, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UserState(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/groupuser/id_group.go b/resource-manager/apimanagement/2024-05-01/groupuser/id_group.go new file mode 100644 index 00000000000..1cacd14ecf9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/id_group.go @@ -0,0 +1,139 @@ +package groupuser + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&GroupId{}) +} + +var _ resourceids.ResourceId = &GroupId{} + +// GroupId is a struct representing the Resource ID for a Group +type GroupId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + GroupId string +} + +// NewGroupID returns a new GroupId struct +func NewGroupID(subscriptionId string, resourceGroupName string, serviceName string, groupId string) GroupId { + return GroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + GroupId: groupId, + } +} + +// ParseGroupID parses 'input' into a GroupId +func ParseGroupID(input string) (*GroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&GroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GroupId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGroupIDInsensitively parses 'input' case-insensitively into a GroupId +// note: this method should only be used for API response data and not user input +func ParseGroupIDInsensitively(input string) (*GroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&GroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GroupId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GroupId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.GroupId, ok = input.Parsed["groupId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupId", input) + } + + return nil +} + +// ValidateGroupID checks that 'input' can be parsed as a Group ID +func ValidateGroupID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Group ID +func (id GroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/groups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.GroupId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Group ID +func (id GroupId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticGroups", "groups", "groups"), + resourceids.UserSpecifiedSegment("groupId", "groupIdValue"), + } +} + +// String returns a human-readable description of this Group ID +func (id GroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Group: %q", id.GroupId), + } + return fmt.Sprintf("Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/groupuser/id_group_test.go b/resource-manager/apimanagement/2024-05-01/groupuser/id_group_test.go new file mode 100644 index 00000000000..7fb837b5225 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/id_group_test.go @@ -0,0 +1,327 @@ +package groupuser + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GroupId{} + +func TestNewGroupID(t *testing.T) { + id := NewGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "groupIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.GroupId != "groupIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'GroupId'", id.GroupId, "groupIdValue") + } +} + +func TestFormatGroupID(t *testing.T) { + actual := NewGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "groupIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups/groupIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GroupId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups/groupIdValue", + Expected: &GroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GroupId: "groupIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups/groupIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGroupID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + } +} + +func TestParseGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GroupId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups/groupIdValue", + Expected: &GroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GroupId: "groupIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups/groupIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gRoUpS/gRoUpIdVaLuE", + Expected: &GroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + GroupId: "gRoUpIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gRoUpS/gRoUpIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGroupIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + } +} + +func TestSegmentsForGroupId(t *testing.T) { + segments := GroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GroupId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/groupuser/id_groupuser.go b/resource-manager/apimanagement/2024-05-01/groupuser/id_groupuser.go new file mode 100644 index 00000000000..57de3d320e8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/id_groupuser.go @@ -0,0 +1,148 @@ +package groupuser + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&GroupUserId{}) +} + +var _ resourceids.ResourceId = &GroupUserId{} + +// GroupUserId is a struct representing the Resource ID for a Group User +type GroupUserId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + GroupId string + UserId string +} + +// NewGroupUserID returns a new GroupUserId struct +func NewGroupUserID(subscriptionId string, resourceGroupName string, serviceName string, groupId string, userId string) GroupUserId { + return GroupUserId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + GroupId: groupId, + UserId: userId, + } +} + +// ParseGroupUserID parses 'input' into a GroupUserId +func ParseGroupUserID(input string) (*GroupUserId, error) { + parser := resourceids.NewParserFromResourceIdType(&GroupUserId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GroupUserId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGroupUserIDInsensitively parses 'input' case-insensitively into a GroupUserId +// note: this method should only be used for API response data and not user input +func ParseGroupUserIDInsensitively(input string) (*GroupUserId, error) { + parser := resourceids.NewParserFromResourceIdType(&GroupUserId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GroupUserId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GroupUserId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.GroupId, ok = input.Parsed["groupId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupId", input) + } + + if id.UserId, ok = input.Parsed["userId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "userId", input) + } + + return nil +} + +// ValidateGroupUserID checks that 'input' can be parsed as a Group User ID +func ValidateGroupUserID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseGroupUserID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Group User ID +func (id GroupUserId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/groups/%s/users/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.GroupId, id.UserId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Group User ID +func (id GroupUserId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticGroups", "groups", "groups"), + resourceids.UserSpecifiedSegment("groupId", "groupIdValue"), + resourceids.StaticSegment("staticUsers", "users", "users"), + resourceids.UserSpecifiedSegment("userId", "userIdValue"), + } +} + +// String returns a human-readable description of this Group User ID +func (id GroupUserId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Group: %q", id.GroupId), + fmt.Sprintf("User: %q", id.UserId), + } + return fmt.Sprintf("Group User (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/groupuser/id_groupuser_test.go b/resource-manager/apimanagement/2024-05-01/groupuser/id_groupuser_test.go new file mode 100644 index 00000000000..a1cfa09e665 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/id_groupuser_test.go @@ -0,0 +1,372 @@ +package groupuser + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GroupUserId{} + +func TestNewGroupUserID(t *testing.T) { + id := NewGroupUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "groupIdValue", "userIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.GroupId != "groupIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'GroupId'", id.GroupId, "groupIdValue") + } + + if id.UserId != "userIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'UserId'", id.UserId, "userIdValue") + } +} + +func TestFormatGroupUserID(t *testing.T) { + actual := NewGroupUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "groupIdValue", "userIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups/groupIdValue/users/userIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGroupUserID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GroupUserId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups/groupIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups/groupIdValue/users", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups/groupIdValue/users/userIdValue", + Expected: &GroupUserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GroupId: "groupIdValue", + UserId: "userIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups/groupIdValue/users/userIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGroupUserID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + if actual.UserId != v.Expected.UserId { + t.Fatalf("Expected %q but got %q for UserId", v.Expected.UserId, actual.UserId) + } + + } +} + +func TestParseGroupUserIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GroupUserId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups/groupIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gRoUpS/gRoUpIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups/groupIdValue/users", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gRoUpS/gRoUpIdVaLuE/uSeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups/groupIdValue/users/userIdValue", + Expected: &GroupUserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + GroupId: "groupIdValue", + UserId: "userIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/groups/groupIdValue/users/userIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gRoUpS/gRoUpIdVaLuE/uSeRs/uSeRiDvAlUe", + Expected: &GroupUserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + GroupId: "gRoUpIdVaLuE", + UserId: "uSeRiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/gRoUpS/gRoUpIdVaLuE/uSeRs/uSeRiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGroupUserIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + if actual.UserId != v.Expected.UserId { + t.Fatalf("Expected %q but got %q for UserId", v.Expected.UserId, actual.UserId) + } + + } +} + +func TestSegmentsForGroupUserId(t *testing.T) { + segments := GroupUserId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GroupUserId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/groupuser/id_workspacegroup.go b/resource-manager/apimanagement/2024-05-01/groupuser/id_workspacegroup.go new file mode 100644 index 00000000000..6c67d5dd6e0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/id_workspacegroup.go @@ -0,0 +1,148 @@ +package groupuser + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceGroupId{}) +} + +var _ resourceids.ResourceId = &WorkspaceGroupId{} + +// WorkspaceGroupId is a struct representing the Resource ID for a Workspace Group +type WorkspaceGroupId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + GroupId string +} + +// NewWorkspaceGroupID returns a new WorkspaceGroupId struct +func NewWorkspaceGroupID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, groupId string) WorkspaceGroupId { + return WorkspaceGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + GroupId: groupId, + } +} + +// ParseWorkspaceGroupID parses 'input' into a WorkspaceGroupId +func ParseWorkspaceGroupID(input string) (*WorkspaceGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceGroupId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceGroupIDInsensitively parses 'input' case-insensitively into a WorkspaceGroupId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceGroupIDInsensitively(input string) (*WorkspaceGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceGroupId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceGroupId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.GroupId, ok = input.Parsed["groupId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupId", input) + } + + return nil +} + +// ValidateWorkspaceGroupID checks that 'input' can be parsed as a Workspace Group ID +func ValidateWorkspaceGroupID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Group ID +func (id WorkspaceGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/groups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.GroupId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Group ID +func (id WorkspaceGroupId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticGroups", "groups", "groups"), + resourceids.UserSpecifiedSegment("groupId", "groupIdValue"), + } +} + +// String returns a human-readable description of this Workspace Group ID +func (id WorkspaceGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Group: %q", id.GroupId), + } + return fmt.Sprintf("Workspace Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/groupuser/id_workspacegroup_test.go b/resource-manager/apimanagement/2024-05-01/groupuser/id_workspacegroup_test.go new file mode 100644 index 00000000000..1718c95df07 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/id_workspacegroup_test.go @@ -0,0 +1,372 @@ +package groupuser + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceGroupId{} + +func TestNewWorkspaceGroupID(t *testing.T) { + id := NewWorkspaceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "groupIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.GroupId != "groupIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'GroupId'", id.GroupId, "groupIdValue") + } +} + +func TestFormatWorkspaceGroupID(t *testing.T) { + actual := NewWorkspaceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "groupIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups/groupIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceGroupId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups/groupIdValue", + Expected: &WorkspaceGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + GroupId: "groupIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups/groupIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceGroupID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + } +} + +func TestParseWorkspaceGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceGroupId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/gRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups/groupIdValue", + Expected: &WorkspaceGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + GroupId: "groupIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups/groupIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/gRoUpS/gRoUpIdVaLuE", + Expected: &WorkspaceGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + GroupId: "gRoUpIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/gRoUpS/gRoUpIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceGroupIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + } +} + +func TestSegmentsForWorkspaceGroupId(t *testing.T) { + segments := WorkspaceGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceGroupId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/groupuser/id_workspacegroupuser.go b/resource-manager/apimanagement/2024-05-01/groupuser/id_workspacegroupuser.go new file mode 100644 index 00000000000..fd00ae51ba3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/id_workspacegroupuser.go @@ -0,0 +1,157 @@ +package groupuser + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceGroupUserId{}) +} + +var _ resourceids.ResourceId = &WorkspaceGroupUserId{} + +// WorkspaceGroupUserId is a struct representing the Resource ID for a Workspace Group User +type WorkspaceGroupUserId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + GroupId string + UserId string +} + +// NewWorkspaceGroupUserID returns a new WorkspaceGroupUserId struct +func NewWorkspaceGroupUserID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, groupId string, userId string) WorkspaceGroupUserId { + return WorkspaceGroupUserId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + GroupId: groupId, + UserId: userId, + } +} + +// ParseWorkspaceGroupUserID parses 'input' into a WorkspaceGroupUserId +func ParseWorkspaceGroupUserID(input string) (*WorkspaceGroupUserId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceGroupUserId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceGroupUserId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceGroupUserIDInsensitively parses 'input' case-insensitively into a WorkspaceGroupUserId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceGroupUserIDInsensitively(input string) (*WorkspaceGroupUserId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceGroupUserId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceGroupUserId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceGroupUserId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.GroupId, ok = input.Parsed["groupId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupId", input) + } + + if id.UserId, ok = input.Parsed["userId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "userId", input) + } + + return nil +} + +// ValidateWorkspaceGroupUserID checks that 'input' can be parsed as a Workspace Group User ID +func ValidateWorkspaceGroupUserID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceGroupUserID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Group User ID +func (id WorkspaceGroupUserId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/groups/%s/users/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.GroupId, id.UserId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Group User ID +func (id WorkspaceGroupUserId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticGroups", "groups", "groups"), + resourceids.UserSpecifiedSegment("groupId", "groupIdValue"), + resourceids.StaticSegment("staticUsers", "users", "users"), + resourceids.UserSpecifiedSegment("userId", "userIdValue"), + } +} + +// String returns a human-readable description of this Workspace Group User ID +func (id WorkspaceGroupUserId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Group: %q", id.GroupId), + fmt.Sprintf("User: %q", id.UserId), + } + return fmt.Sprintf("Workspace Group User (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/groupuser/id_workspacegroupuser_test.go b/resource-manager/apimanagement/2024-05-01/groupuser/id_workspacegroupuser_test.go new file mode 100644 index 00000000000..8681218b7f4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/id_workspacegroupuser_test.go @@ -0,0 +1,417 @@ +package groupuser + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceGroupUserId{} + +func TestNewWorkspaceGroupUserID(t *testing.T) { + id := NewWorkspaceGroupUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "groupIdValue", "userIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.GroupId != "groupIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'GroupId'", id.GroupId, "groupIdValue") + } + + if id.UserId != "userIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'UserId'", id.UserId, "userIdValue") + } +} + +func TestFormatWorkspaceGroupUserID(t *testing.T) { + actual := NewWorkspaceGroupUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "groupIdValue", "userIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups/groupIdValue/users/userIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceGroupUserID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceGroupUserId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups/groupIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups/groupIdValue/users", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups/groupIdValue/users/userIdValue", + Expected: &WorkspaceGroupUserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + GroupId: "groupIdValue", + UserId: "userIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups/groupIdValue/users/userIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceGroupUserID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + if actual.UserId != v.Expected.UserId { + t.Fatalf("Expected %q but got %q for UserId", v.Expected.UserId, actual.UserId) + } + + } +} + +func TestParseWorkspaceGroupUserIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceGroupUserId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/gRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups/groupIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/gRoUpS/gRoUpIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups/groupIdValue/users", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/gRoUpS/gRoUpIdVaLuE/uSeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups/groupIdValue/users/userIdValue", + Expected: &WorkspaceGroupUserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + GroupId: "groupIdValue", + UserId: "userIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/groups/groupIdValue/users/userIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/gRoUpS/gRoUpIdVaLuE/uSeRs/uSeRiDvAlUe", + Expected: &WorkspaceGroupUserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + GroupId: "gRoUpIdVaLuE", + UserId: "uSeRiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/gRoUpS/gRoUpIdVaLuE/uSeRs/uSeRiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceGroupUserIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + if actual.UserId != v.Expected.UserId { + t.Fatalf("Expected %q but got %q for UserId", v.Expected.UserId, actual.UserId) + } + + } +} + +func TestSegmentsForWorkspaceGroupUserId(t *testing.T) { + segments := WorkspaceGroupUserId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceGroupUserId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/groupuser/method_checkentityexists.go b/resource-manager/apimanagement/2024-05-01/groupuser/method_checkentityexists.go new file mode 100644 index 00000000000..ecf5ac1f37b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/method_checkentityexists.go @@ -0,0 +1,46 @@ +package groupuser + +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 CheckEntityExistsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CheckEntityExists ... +func (c GroupUserClient) CheckEntityExists(ctx context.Context, id GroupUserId) (result CheckEntityExistsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/groupuser/method_create.go b/resource-manager/apimanagement/2024-05-01/groupuser/method_create.go new file mode 100644 index 00000000000..6dc8112254d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/method_create.go @@ -0,0 +1,55 @@ +package groupuser + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *UserContract +} + +// Create ... +func (c GroupUserClient) Create(ctx context.Context, id GroupUserId) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model UserContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/groupuser/method_delete.go b/resource-manager/apimanagement/2024-05-01/groupuser/method_delete.go new file mode 100644 index 00000000000..e8513f36120 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/method_delete.go @@ -0,0 +1,47 @@ +package groupuser + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c GroupUserClient) Delete(ctx context.Context, id GroupUserId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/groupuser/method_list.go b/resource-manager/apimanagement/2024-05-01/groupuser/method_list.go new file mode 100644 index 00000000000..b2f4d682063 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/method_list.go @@ -0,0 +1,141 @@ +package groupuser + +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 *[]UserContract +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []UserContract +} + +type ListOperationOptions struct { + Filter *string + Skip *int64 + 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.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c GroupUserClient) List(ctx context.Context, id GroupId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/users", 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 *[]UserContract `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 GroupUserClient) ListComplete(ctx context.Context, id GroupId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, UserContractOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c GroupUserClient) ListCompleteMatchingPredicate(ctx context.Context, id GroupId, options ListOperationOptions, predicate UserContractOperationPredicate) (result ListCompleteResult, err error) { + items := make([]UserContract, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/groupuser/method_workspacegroupusercheckentityexists.go b/resource-manager/apimanagement/2024-05-01/groupuser/method_workspacegroupusercheckentityexists.go new file mode 100644 index 00000000000..20cf84facda --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/method_workspacegroupusercheckentityexists.go @@ -0,0 +1,46 @@ +package groupuser + +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 WorkspaceGroupUserCheckEntityExistsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceGroupUserCheckEntityExists ... +func (c GroupUserClient) WorkspaceGroupUserCheckEntityExists(ctx context.Context, id WorkspaceGroupUserId) (result WorkspaceGroupUserCheckEntityExistsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/groupuser/method_workspacegroupusercreate.go b/resource-manager/apimanagement/2024-05-01/groupuser/method_workspacegroupusercreate.go new file mode 100644 index 00000000000..dd73551832d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/method_workspacegroupusercreate.go @@ -0,0 +1,55 @@ +package groupuser + +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 WorkspaceGroupUserCreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *UserContract +} + +// WorkspaceGroupUserCreate ... +func (c GroupUserClient) WorkspaceGroupUserCreate(ctx context.Context, id WorkspaceGroupUserId) (result WorkspaceGroupUserCreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model UserContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/groupuser/method_workspacegroupuserdelete.go b/resource-manager/apimanagement/2024-05-01/groupuser/method_workspacegroupuserdelete.go new file mode 100644 index 00000000000..7de0c852b37 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/method_workspacegroupuserdelete.go @@ -0,0 +1,47 @@ +package groupuser + +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 WorkspaceGroupUserDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceGroupUserDelete ... +func (c GroupUserClient) WorkspaceGroupUserDelete(ctx context.Context, id WorkspaceGroupUserId) (result WorkspaceGroupUserDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/groupuser/method_workspacegroupuserlist.go b/resource-manager/apimanagement/2024-05-01/groupuser/method_workspacegroupuserlist.go new file mode 100644 index 00000000000..c4e2a527039 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/method_workspacegroupuserlist.go @@ -0,0 +1,141 @@ +package groupuser + +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 WorkspaceGroupUserListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]UserContract +} + +type WorkspaceGroupUserListCompleteResult struct { + LatestHttpResponse *http.Response + Items []UserContract +} + +type WorkspaceGroupUserListOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultWorkspaceGroupUserListOperationOptions() WorkspaceGroupUserListOperationOptions { + return WorkspaceGroupUserListOperationOptions{} +} + +func (o WorkspaceGroupUserListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceGroupUserListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceGroupUserListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspaceGroupUserListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceGroupUserListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceGroupUserList ... +func (c GroupUserClient) WorkspaceGroupUserList(ctx context.Context, id WorkspaceGroupId, options WorkspaceGroupUserListOperationOptions) (result WorkspaceGroupUserListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspaceGroupUserListCustomPager{}, + Path: fmt.Sprintf("%s/users", 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 *[]UserContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceGroupUserListComplete retrieves all the results into a single object +func (c GroupUserClient) WorkspaceGroupUserListComplete(ctx context.Context, id WorkspaceGroupId, options WorkspaceGroupUserListOperationOptions) (WorkspaceGroupUserListCompleteResult, error) { + return c.WorkspaceGroupUserListCompleteMatchingPredicate(ctx, id, options, UserContractOperationPredicate{}) +} + +// WorkspaceGroupUserListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c GroupUserClient) WorkspaceGroupUserListCompleteMatchingPredicate(ctx context.Context, id WorkspaceGroupId, options WorkspaceGroupUserListOperationOptions, predicate UserContractOperationPredicate) (result WorkspaceGroupUserListCompleteResult, err error) { + items := make([]UserContract, 0) + + resp, err := c.WorkspaceGroupUserList(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceGroupUserListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/groupuser/model_groupcontractproperties.go b/resource-manager/apimanagement/2024-05-01/groupuser/model_groupcontractproperties.go new file mode 100644 index 00000000000..a734b3f8f74 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/model_groupcontractproperties.go @@ -0,0 +1,12 @@ +package groupuser + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupContractProperties struct { + BuiltIn *bool `json:"builtIn,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName string `json:"displayName"` + ExternalId *string `json:"externalId,omitempty"` + Type *GroupType `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/groupuser/model_usercontract.go b/resource-manager/apimanagement/2024-05-01/groupuser/model_usercontract.go new file mode 100644 index 00000000000..1da87de7aeb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/model_usercontract.go @@ -0,0 +1,11 @@ +package groupuser + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *UserContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/groupuser/model_usercontractproperties.go b/resource-manager/apimanagement/2024-05-01/groupuser/model_usercontractproperties.go new file mode 100644 index 00000000000..11eac96a912 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/model_usercontractproperties.go @@ -0,0 +1,33 @@ +package groupuser + +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 UserContractProperties struct { + Email *string `json:"email,omitempty"` + FirstName *string `json:"firstName,omitempty"` + Groups *[]GroupContractProperties `json:"groups,omitempty"` + Identities *[]UserIdentityContract `json:"identities,omitempty"` + LastName *string `json:"lastName,omitempty"` + Note *string `json:"note,omitempty"` + RegistrationDate *string `json:"registrationDate,omitempty"` + State *UserState `json:"state,omitempty"` +} + +func (o *UserContractProperties) GetRegistrationDateAsTime() (*time.Time, error) { + if o.RegistrationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RegistrationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *UserContractProperties) SetRegistrationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RegistrationDate = &formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/groupuser/model_useridentitycontract.go b/resource-manager/apimanagement/2024-05-01/groupuser/model_useridentitycontract.go new file mode 100644 index 00000000000..fb1d5a656ad --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/model_useridentitycontract.go @@ -0,0 +1,9 @@ +package groupuser + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserIdentityContract struct { + Id *string `json:"id,omitempty"` + Provider *string `json:"provider,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/groupuser/predicates.go b/resource-manager/apimanagement/2024-05-01/groupuser/predicates.go new file mode 100644 index 00000000000..c2691a6325d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/predicates.go @@ -0,0 +1,27 @@ +package groupuser + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p UserContractOperationPredicate) Matches(input UserContract) 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/apimanagement/2024-05-01/groupuser/version.go b/resource-manager/apimanagement/2024-05-01/groupuser/version.go new file mode 100644 index 00000000000..497e67b752d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/groupuser/version.go @@ -0,0 +1,12 @@ +package groupuser + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/groupuser/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/identityprovider/README.md b/resource-manager/apimanagement/2024-05-01/identityprovider/README.md new file mode 100644 index 00000000000..e00153a79c4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/identityprovider/README.md @@ -0,0 +1,143 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/identityprovider` Documentation + +The `identityprovider` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/identityprovider" +``` + + +### Client Initialization + +```go +client := identityprovider.NewIdentityProviderClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `IdentityProviderClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := identityprovider.NewIdentityProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "aad") + +payload := identityprovider.IdentityProviderCreateContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, identityprovider.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IdentityProviderClient.Delete` + +```go +ctx := context.TODO() +id := identityprovider.NewIdentityProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "aad") + +read, err := client.Delete(ctx, id, identityprovider.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IdentityProviderClient.Get` + +```go +ctx := context.TODO() +id := identityprovider.NewIdentityProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "aad") + +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: `IdentityProviderClient.GetEntityTag` + +```go +ctx := context.TODO() +id := identityprovider.NewIdentityProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "aad") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IdentityProviderClient.ListByService` + +```go +ctx := context.TODO() +id := identityprovider.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id)` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `IdentityProviderClient.ListSecrets` + +```go +ctx := context.TODO() +id := identityprovider.NewIdentityProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "aad") + +read, err := client.ListSecrets(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IdentityProviderClient.Update` + +```go +ctx := context.TODO() +id := identityprovider.NewIdentityProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "aad") + +payload := identityprovider.IdentityProviderUpdateParameters{ + // ... +} + + +read, err := client.Update(ctx, id, payload, identityprovider.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/identityprovider/client.go b/resource-manager/apimanagement/2024-05-01/identityprovider/client.go new file mode 100644 index 00000000000..ba2ed8bbee1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/identityprovider/client.go @@ -0,0 +1,26 @@ +package identityprovider + +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 IdentityProviderClient struct { + Client *resourcemanager.Client +} + +func NewIdentityProviderClientWithBaseURI(sdkApi sdkEnv.Api) (*IdentityProviderClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "identityprovider", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IdentityProviderClient: %+v", err) + } + + return &IdentityProviderClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/identityprovider/constants.go b/resource-manager/apimanagement/2024-05-01/identityprovider/constants.go new file mode 100644 index 00000000000..d96fcd03253 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/identityprovider/constants.go @@ -0,0 +1,63 @@ +package identityprovider + +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 IdentityProviderType string + +const ( + IdentityProviderTypeAad IdentityProviderType = "aad" + IdentityProviderTypeAadBTwoC IdentityProviderType = "aadB2C" + IdentityProviderTypeFacebook IdentityProviderType = "facebook" + IdentityProviderTypeGoogle IdentityProviderType = "google" + IdentityProviderTypeMicrosoft IdentityProviderType = "microsoft" + IdentityProviderTypeTwitter IdentityProviderType = "twitter" +) + +func PossibleValuesForIdentityProviderType() []string { + return []string{ + string(IdentityProviderTypeAad), + string(IdentityProviderTypeAadBTwoC), + string(IdentityProviderTypeFacebook), + string(IdentityProviderTypeGoogle), + string(IdentityProviderTypeMicrosoft), + string(IdentityProviderTypeTwitter), + } +} + +func (s *IdentityProviderType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIdentityProviderType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIdentityProviderType(input string) (*IdentityProviderType, error) { + vals := map[string]IdentityProviderType{ + "aad": IdentityProviderTypeAad, + "aadb2c": IdentityProviderTypeAadBTwoC, + "facebook": IdentityProviderTypeFacebook, + "google": IdentityProviderTypeGoogle, + "microsoft": IdentityProviderTypeMicrosoft, + "twitter": IdentityProviderTypeTwitter, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IdentityProviderType(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/identityprovider/id_identityprovider.go b/resource-manager/apimanagement/2024-05-01/identityprovider/id_identityprovider.go new file mode 100644 index 00000000000..3d474aaec02 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/identityprovider/id_identityprovider.go @@ -0,0 +1,147 @@ +package identityprovider + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&IdentityProviderId{}) +} + +var _ resourceids.ResourceId = &IdentityProviderId{} + +// IdentityProviderId is a struct representing the Resource ID for a Identity Provider +type IdentityProviderId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + IdentityProviderName IdentityProviderType +} + +// NewIdentityProviderID returns a new IdentityProviderId struct +func NewIdentityProviderID(subscriptionId string, resourceGroupName string, serviceName string, identityProviderName IdentityProviderType) IdentityProviderId { + return IdentityProviderId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + IdentityProviderName: identityProviderName, + } +} + +// ParseIdentityProviderID parses 'input' into a IdentityProviderId +func ParseIdentityProviderID(input string) (*IdentityProviderId, error) { + parser := resourceids.NewParserFromResourceIdType(&IdentityProviderId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IdentityProviderId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseIdentityProviderIDInsensitively parses 'input' case-insensitively into a IdentityProviderId +// note: this method should only be used for API response data and not user input +func ParseIdentityProviderIDInsensitively(input string) (*IdentityProviderId, error) { + parser := resourceids.NewParserFromResourceIdType(&IdentityProviderId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IdentityProviderId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *IdentityProviderId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if v, ok := input.Parsed["identityProviderName"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "identityProviderName", input) + } + + identityProviderName, err := parseIdentityProviderType(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.IdentityProviderName = *identityProviderName + } + + return nil +} + +// ValidateIdentityProviderID checks that 'input' can be parsed as a Identity Provider ID +func ValidateIdentityProviderID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseIdentityProviderID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Identity Provider ID +func (id IdentityProviderId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/identityProviders/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, string(id.IdentityProviderName)) +} + +// Segments returns a slice of Resource ID Segments which comprise this Identity Provider ID +func (id IdentityProviderId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticIdentityProviders", "identityProviders", "identityProviders"), + resourceids.ConstantSegment("identityProviderName", PossibleValuesForIdentityProviderType(), "aad"), + } +} + +// String returns a human-readable description of this Identity Provider ID +func (id IdentityProviderId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Identity Provider Name: %q", string(id.IdentityProviderName)), + } + return fmt.Sprintf("Identity Provider (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/identityprovider/id_identityprovider_test.go b/resource-manager/apimanagement/2024-05-01/identityprovider/id_identityprovider_test.go new file mode 100644 index 00000000000..dfd4275c905 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/identityprovider/id_identityprovider_test.go @@ -0,0 +1,327 @@ +package identityprovider + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &IdentityProviderId{} + +func TestNewIdentityProviderID(t *testing.T) { + id := NewIdentityProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "aad") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.IdentityProviderName != "aad" { + t.Fatalf("Expected %q but got %q for Segment 'IdentityProviderName'", id.IdentityProviderName, "aad") + } +} + +func TestFormatIdentityProviderID(t *testing.T) { + actual := NewIdentityProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "aad").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/identityProviders/aad" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseIdentityProviderID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IdentityProviderId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/identityProviders", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/identityProviders/aad", + Expected: &IdentityProviderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + IdentityProviderName: "aad", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/identityProviders/aad/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIdentityProviderID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.IdentityProviderName != v.Expected.IdentityProviderName { + t.Fatalf("Expected %q but got %q for IdentityProviderName", v.Expected.IdentityProviderName, actual.IdentityProviderName) + } + + } +} + +func TestParseIdentityProviderIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IdentityProviderId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/identityProviders", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/iDeNtItYpRoViDeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/identityProviders/aad", + Expected: &IdentityProviderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + IdentityProviderName: "aad", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/identityProviders/aad/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/iDeNtItYpRoViDeRs/aAd", + Expected: &IdentityProviderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + IdentityProviderName: "aad", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/iDeNtItYpRoViDeRs/aAd/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIdentityProviderIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.IdentityProviderName != v.Expected.IdentityProviderName { + t.Fatalf("Expected %q but got %q for IdentityProviderName", v.Expected.IdentityProviderName, actual.IdentityProviderName) + } + + } +} + +func TestSegmentsForIdentityProviderId(t *testing.T) { + segments := IdentityProviderId{}.Segments() + if len(segments) == 0 { + t.Fatalf("IdentityProviderId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/identityprovider/id_service.go b/resource-manager/apimanagement/2024-05-01/identityprovider/id_service.go new file mode 100644 index 00000000000..8276034f3e7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/identityprovider/id_service.go @@ -0,0 +1,130 @@ +package identityprovider + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/identityprovider/id_service_test.go b/resource-manager/apimanagement/2024-05-01/identityprovider/id_service_test.go new file mode 100644 index 00000000000..deffab6f17d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/identityprovider/id_service_test.go @@ -0,0 +1,282 @@ +package identityprovider + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/identityprovider/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/identityprovider/method_createorupdate.go new file mode 100644 index 00000000000..834adf0fae9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/identityprovider/method_createorupdate.go @@ -0,0 +1,88 @@ +package identityprovider + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IdentityProviderContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c IdentityProviderClient) CreateOrUpdate(ctx context.Context, id IdentityProviderId, input IdentityProviderCreateContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 IdentityProviderContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/identityprovider/method_delete.go b/resource-manager/apimanagement/2024-05-01/identityprovider/method_delete.go new file mode 100644 index 00000000000..825d432de2b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/identityprovider/method_delete.go @@ -0,0 +1,76 @@ +package identityprovider + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c IdentityProviderClient) Delete(ctx context.Context, id IdentityProviderId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/identityprovider/method_get.go b/resource-manager/apimanagement/2024-05-01/identityprovider/method_get.go new file mode 100644 index 00000000000..a7550d92bb0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/identityprovider/method_get.go @@ -0,0 +1,54 @@ +package identityprovider + +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 *IdentityProviderContract +} + +// Get ... +func (c IdentityProviderClient) Get(ctx context.Context, id IdentityProviderId) (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 IdentityProviderContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/identityprovider/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/identityprovider/method_getentitytag.go new file mode 100644 index 00000000000..626d199ac1f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/identityprovider/method_getentitytag.go @@ -0,0 +1,46 @@ +package identityprovider + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c IdentityProviderClient) GetEntityTag(ctx context.Context, id IdentityProviderId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/identityprovider/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/identityprovider/method_listbyservice.go new file mode 100644 index 00000000000..25e8a873460 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/identityprovider/method_listbyservice.go @@ -0,0 +1,105 @@ +package identityprovider + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]IdentityProviderContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []IdentityProviderContract +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c IdentityProviderClient) ListByService(ctx context.Context, id ServiceId) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/identityProviders", 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 *[]IdentityProviderContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c IdentityProviderClient) ListByServiceComplete(ctx context.Context, id ServiceId) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, IdentityProviderContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IdentityProviderClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, predicate IdentityProviderContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]IdentityProviderContract, 0) + + resp, err := c.ListByService(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/identityprovider/method_listsecrets.go b/resource-manager/apimanagement/2024-05-01/identityprovider/method_listsecrets.go new file mode 100644 index 00000000000..284d5e3aa2b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/identityprovider/method_listsecrets.go @@ -0,0 +1,55 @@ +package identityprovider + +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 ListSecretsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ClientSecretContract +} + +// ListSecrets ... +func (c IdentityProviderClient) ListSecrets(ctx context.Context, id IdentityProviderId) (result ListSecretsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listSecrets", 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 ClientSecretContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/identityprovider/method_update.go b/resource-manager/apimanagement/2024-05-01/identityprovider/method_update.go new file mode 100644 index 00000000000..ac8db539b33 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/identityprovider/method_update.go @@ -0,0 +1,87 @@ +package identityprovider + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IdentityProviderContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c IdentityProviderClient) Update(ctx context.Context, id IdentityProviderId, input IdentityProviderUpdateParameters, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 IdentityProviderContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/identityprovider/model_clientsecretcontract.go b/resource-manager/apimanagement/2024-05-01/identityprovider/model_clientsecretcontract.go new file mode 100644 index 00000000000..8ab3fa47bc0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/identityprovider/model_clientsecretcontract.go @@ -0,0 +1,8 @@ +package identityprovider + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClientSecretContract struct { + ClientSecret *string `json:"clientSecret,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/identityprovider/model_identityprovidercontract.go b/resource-manager/apimanagement/2024-05-01/identityprovider/model_identityprovidercontract.go new file mode 100644 index 00000000000..8191ccfc8b7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/identityprovider/model_identityprovidercontract.go @@ -0,0 +1,11 @@ +package identityprovider + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityProviderContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *IdentityProviderContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/identityprovider/model_identityprovidercontractproperties.go b/resource-manager/apimanagement/2024-05-01/identityprovider/model_identityprovidercontractproperties.go new file mode 100644 index 00000000000..0e8d1f6c457 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/identityprovider/model_identityprovidercontractproperties.go @@ -0,0 +1,18 @@ +package identityprovider + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityProviderContractProperties struct { + AllowedTenants *[]string `json:"allowedTenants,omitempty"` + Authority *string `json:"authority,omitempty"` + ClientId string `json:"clientId"` + ClientLibrary *string `json:"clientLibrary,omitempty"` + ClientSecret *string `json:"clientSecret,omitempty"` + PasswordResetPolicyName *string `json:"passwordResetPolicyName,omitempty"` + ProfileEditingPolicyName *string `json:"profileEditingPolicyName,omitempty"` + SigninPolicyName *string `json:"signinPolicyName,omitempty"` + SigninTenant *string `json:"signinTenant,omitempty"` + SignupPolicyName *string `json:"signupPolicyName,omitempty"` + Type *IdentityProviderType `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/identityprovider/model_identityprovidercreatecontract.go b/resource-manager/apimanagement/2024-05-01/identityprovider/model_identityprovidercreatecontract.go new file mode 100644 index 00000000000..c0a6875caa4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/identityprovider/model_identityprovidercreatecontract.go @@ -0,0 +1,11 @@ +package identityprovider + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityProviderCreateContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *IdentityProviderCreateContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/identityprovider/model_identityprovidercreatecontractproperties.go b/resource-manager/apimanagement/2024-05-01/identityprovider/model_identityprovidercreatecontractproperties.go new file mode 100644 index 00000000000..6d1c289428c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/identityprovider/model_identityprovidercreatecontractproperties.go @@ -0,0 +1,18 @@ +package identityprovider + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityProviderCreateContractProperties struct { + AllowedTenants *[]string `json:"allowedTenants,omitempty"` + Authority *string `json:"authority,omitempty"` + ClientId string `json:"clientId"` + ClientLibrary *string `json:"clientLibrary,omitempty"` + ClientSecret string `json:"clientSecret"` + PasswordResetPolicyName *string `json:"passwordResetPolicyName,omitempty"` + ProfileEditingPolicyName *string `json:"profileEditingPolicyName,omitempty"` + SigninPolicyName *string `json:"signinPolicyName,omitempty"` + SigninTenant *string `json:"signinTenant,omitempty"` + SignupPolicyName *string `json:"signupPolicyName,omitempty"` + Type *IdentityProviderType `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/identityprovider/model_identityproviderupdateparameters.go b/resource-manager/apimanagement/2024-05-01/identityprovider/model_identityproviderupdateparameters.go new file mode 100644 index 00000000000..d7e0a9d4548 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/identityprovider/model_identityproviderupdateparameters.go @@ -0,0 +1,8 @@ +package identityprovider + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityProviderUpdateParameters struct { + Properties *IdentityProviderUpdateProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/identityprovider/model_identityproviderupdateproperties.go b/resource-manager/apimanagement/2024-05-01/identityprovider/model_identityproviderupdateproperties.go new file mode 100644 index 00000000000..d46eea9c1d5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/identityprovider/model_identityproviderupdateproperties.go @@ -0,0 +1,18 @@ +package identityprovider + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityProviderUpdateProperties struct { + AllowedTenants *[]string `json:"allowedTenants,omitempty"` + Authority *string `json:"authority,omitempty"` + ClientId *string `json:"clientId,omitempty"` + ClientLibrary *string `json:"clientLibrary,omitempty"` + ClientSecret *string `json:"clientSecret,omitempty"` + PasswordResetPolicyName *string `json:"passwordResetPolicyName,omitempty"` + ProfileEditingPolicyName *string `json:"profileEditingPolicyName,omitempty"` + SigninPolicyName *string `json:"signinPolicyName,omitempty"` + SigninTenant *string `json:"signinTenant,omitempty"` + SignupPolicyName *string `json:"signupPolicyName,omitempty"` + Type *IdentityProviderType `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/identityprovider/predicates.go b/resource-manager/apimanagement/2024-05-01/identityprovider/predicates.go new file mode 100644 index 00000000000..106538ef5e6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/identityprovider/predicates.go @@ -0,0 +1,27 @@ +package identityprovider + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityProviderContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p IdentityProviderContractOperationPredicate) Matches(input IdentityProviderContract) 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/apimanagement/2024-05-01/identityprovider/version.go b/resource-manager/apimanagement/2024-05-01/identityprovider/version.go new file mode 100644 index 00000000000..bd9affc1c41 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/identityprovider/version.go @@ -0,0 +1,12 @@ +package identityprovider + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/identityprovider/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/issue/README.md b/resource-manager/apimanagement/2024-05-01/issue/README.md new file mode 100644 index 00000000000..63eba0197cc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/issue/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/issue` Documentation + +The `issue` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/issue" +``` + + +### Client Initialization + +```go +client := issue.NewIssueClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `IssueClient.Get` + +```go +ctx := context.TODO() +id := issue.NewIssueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "issueIdValue") + +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: `IssueClient.ListByService` + +```go +ctx := context.TODO() +id := issue.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, issue.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, issue.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/issue/client.go b/resource-manager/apimanagement/2024-05-01/issue/client.go new file mode 100644 index 00000000000..cb06d0ebaca --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/issue/client.go @@ -0,0 +1,26 @@ +package issue + +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 IssueClient struct { + Client *resourcemanager.Client +} + +func NewIssueClientWithBaseURI(sdkApi sdkEnv.Api) (*IssueClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "issue", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IssueClient: %+v", err) + } + + return &IssueClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/issue/constants.go b/resource-manager/apimanagement/2024-05-01/issue/constants.go new file mode 100644 index 00000000000..737222a81b0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/issue/constants.go @@ -0,0 +1,60 @@ +package issue + +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 State string + +const ( + StateClosed State = "closed" + StateOpen State = "open" + StateProposed State = "proposed" + StateRemoved State = "removed" + StateResolved State = "resolved" +) + +func PossibleValuesForState() []string { + return []string{ + string(StateClosed), + string(StateOpen), + string(StateProposed), + string(StateRemoved), + string(StateResolved), + } +} + +func (s *State) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseState(input string) (*State, error) { + vals := map[string]State{ + "closed": StateClosed, + "open": StateOpen, + "proposed": StateProposed, + "removed": StateRemoved, + "resolved": StateResolved, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := State(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/issue/id_issue.go b/resource-manager/apimanagement/2024-05-01/issue/id_issue.go new file mode 100644 index 00000000000..45eb9485335 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/issue/id_issue.go @@ -0,0 +1,139 @@ +package issue + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&IssueId{}) +} + +var _ resourceids.ResourceId = &IssueId{} + +// IssueId is a struct representing the Resource ID for a Issue +type IssueId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + IssueId string +} + +// NewIssueID returns a new IssueId struct +func NewIssueID(subscriptionId string, resourceGroupName string, serviceName string, issueId string) IssueId { + return IssueId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + IssueId: issueId, + } +} + +// ParseIssueID parses 'input' into a IssueId +func ParseIssueID(input string) (*IssueId, error) { + parser := resourceids.NewParserFromResourceIdType(&IssueId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IssueId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseIssueIDInsensitively parses 'input' case-insensitively into a IssueId +// note: this method should only be used for API response data and not user input +func ParseIssueIDInsensitively(input string) (*IssueId, error) { + parser := resourceids.NewParserFromResourceIdType(&IssueId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IssueId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *IssueId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.IssueId, ok = input.Parsed["issueId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "issueId", input) + } + + return nil +} + +// ValidateIssueID checks that 'input' can be parsed as a Issue ID +func ValidateIssueID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseIssueID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Issue ID +func (id IssueId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/issues/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.IssueId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Issue ID +func (id IssueId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticIssues", "issues", "issues"), + resourceids.UserSpecifiedSegment("issueId", "issueIdValue"), + } +} + +// String returns a human-readable description of this Issue ID +func (id IssueId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Issue: %q", id.IssueId), + } + return fmt.Sprintf("Issue (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/issue/id_issue_test.go b/resource-manager/apimanagement/2024-05-01/issue/id_issue_test.go new file mode 100644 index 00000000000..6143c79805f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/issue/id_issue_test.go @@ -0,0 +1,327 @@ +package issue + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &IssueId{} + +func TestNewIssueID(t *testing.T) { + id := NewIssueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "issueIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.IssueId != "issueIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'IssueId'", id.IssueId, "issueIdValue") + } +} + +func TestFormatIssueID(t *testing.T) { + actual := NewIssueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "issueIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/issues/issueIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseIssueID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IssueId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/issues", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/issues/issueIdValue", + Expected: &IssueId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + IssueId: "issueIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/issues/issueIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIssueID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.IssueId != v.Expected.IssueId { + t.Fatalf("Expected %q but got %q for IssueId", v.Expected.IssueId, actual.IssueId) + } + + } +} + +func TestParseIssueIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IssueId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/issues", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/iSsUeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/issues/issueIdValue", + Expected: &IssueId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + IssueId: "issueIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/issues/issueIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/iSsUeS/iSsUeIdVaLuE", + Expected: &IssueId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + IssueId: "iSsUeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/iSsUeS/iSsUeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIssueIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.IssueId != v.Expected.IssueId { + t.Fatalf("Expected %q but got %q for IssueId", v.Expected.IssueId, actual.IssueId) + } + + } +} + +func TestSegmentsForIssueId(t *testing.T) { + segments := IssueId{}.Segments() + if len(segments) == 0 { + t.Fatalf("IssueId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/issue/id_service.go b/resource-manager/apimanagement/2024-05-01/issue/id_service.go new file mode 100644 index 00000000000..88e8a90de0c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/issue/id_service.go @@ -0,0 +1,130 @@ +package issue + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/issue/id_service_test.go b/resource-manager/apimanagement/2024-05-01/issue/id_service_test.go new file mode 100644 index 00000000000..69ba35b5544 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/issue/id_service_test.go @@ -0,0 +1,282 @@ +package issue + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/issue/method_get.go b/resource-manager/apimanagement/2024-05-01/issue/method_get.go new file mode 100644 index 00000000000..69cfbc200fa --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/issue/method_get.go @@ -0,0 +1,54 @@ +package issue + +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 *IssueContract +} + +// Get ... +func (c IssueClient) Get(ctx context.Context, id IssueId) (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 IssueContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/issue/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/issue/method_listbyservice.go new file mode 100644 index 00000000000..bdf1aa92398 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/issue/method_listbyservice.go @@ -0,0 +1,141 @@ +package issue + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]IssueContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []IssueContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c IssueClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/issues", 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 *[]IssueContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c IssueClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, IssueContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IssueClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate IssueContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]IssueContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/issue/model_issuecontract.go b/resource-manager/apimanagement/2024-05-01/issue/model_issuecontract.go new file mode 100644 index 00000000000..887898aec30 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/issue/model_issuecontract.go @@ -0,0 +1,11 @@ +package issue + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IssueContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *IssueContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/issue/model_issuecontractproperties.go b/resource-manager/apimanagement/2024-05-01/issue/model_issuecontractproperties.go new file mode 100644 index 00000000000..7be6fd0dc91 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/issue/model_issuecontractproperties.go @@ -0,0 +1,31 @@ +package issue + +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 IssueContractProperties struct { + ApiId *string `json:"apiId,omitempty"` + CreatedDate *string `json:"createdDate,omitempty"` + Description string `json:"description"` + State *State `json:"state,omitempty"` + Title string `json:"title"` + UserId string `json:"userId"` +} + +func (o *IssueContractProperties) GetCreatedDateAsTime() (*time.Time, error) { + if o.CreatedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *IssueContractProperties) SetCreatedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedDate = &formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/issue/predicates.go b/resource-manager/apimanagement/2024-05-01/issue/predicates.go new file mode 100644 index 00000000000..f0a8d6f81ad --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/issue/predicates.go @@ -0,0 +1,27 @@ +package issue + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IssueContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p IssueContractOperationPredicate) Matches(input IssueContract) 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/apimanagement/2024-05-01/issue/version.go b/resource-manager/apimanagement/2024-05-01/issue/version.go new file mode 100644 index 00000000000..cbf44284e94 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/issue/version.go @@ -0,0 +1,12 @@ +package issue + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/issue/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/README.md b/resource-manager/apimanagement/2024-05-01/logger/README.md new file mode 100644 index 00000000000..655743d0083 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/README.md @@ -0,0 +1,234 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/logger` Documentation + +The `logger` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/logger" +``` + + +### Client Initialization + +```go +client := logger.NewLoggerClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `LoggerClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := logger.NewLoggerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "loggerIdValue") + +payload := logger.LoggerContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, logger.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `LoggerClient.Delete` + +```go +ctx := context.TODO() +id := logger.NewLoggerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "loggerIdValue") + +read, err := client.Delete(ctx, id, logger.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `LoggerClient.Get` + +```go +ctx := context.TODO() +id := logger.NewLoggerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "loggerIdValue") + +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: `LoggerClient.GetEntityTag` + +```go +ctx := context.TODO() +id := logger.NewLoggerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "loggerIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `LoggerClient.ListByService` + +```go +ctx := context.TODO() +id := logger.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, logger.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, logger.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `LoggerClient.Update` + +```go +ctx := context.TODO() +id := logger.NewLoggerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "loggerIdValue") + +payload := logger.LoggerUpdateContract{ + // ... +} + + +read, err := client.Update(ctx, id, payload, logger.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `LoggerClient.WorkspaceLoggerCreateOrUpdate` + +```go +ctx := context.TODO() +id := logger.NewWorkspaceLoggerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "loggerIdValue") + +payload := logger.LoggerContract{ + // ... +} + + +read, err := client.WorkspaceLoggerCreateOrUpdate(ctx, id, payload, logger.DefaultWorkspaceLoggerCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `LoggerClient.WorkspaceLoggerDelete` + +```go +ctx := context.TODO() +id := logger.NewWorkspaceLoggerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "loggerIdValue") + +read, err := client.WorkspaceLoggerDelete(ctx, id, logger.DefaultWorkspaceLoggerDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `LoggerClient.WorkspaceLoggerGet` + +```go +ctx := context.TODO() +id := logger.NewWorkspaceLoggerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "loggerIdValue") + +read, err := client.WorkspaceLoggerGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `LoggerClient.WorkspaceLoggerGetEntityTag` + +```go +ctx := context.TODO() +id := logger.NewWorkspaceLoggerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "loggerIdValue") + +read, err := client.WorkspaceLoggerGetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `LoggerClient.WorkspaceLoggerListByWorkspace` + +```go +ctx := context.TODO() +id := logger.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +// alternatively `client.WorkspaceLoggerListByWorkspace(ctx, id, logger.DefaultWorkspaceLoggerListByWorkspaceOperationOptions())` can be used to do batched pagination +items, err := client.WorkspaceLoggerListByWorkspaceComplete(ctx, id, logger.DefaultWorkspaceLoggerListByWorkspaceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `LoggerClient.WorkspaceLoggerUpdate` + +```go +ctx := context.TODO() +id := logger.NewWorkspaceLoggerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "loggerIdValue") + +payload := logger.LoggerUpdateContract{ + // ... +} + + +read, err := client.WorkspaceLoggerUpdate(ctx, id, payload, logger.DefaultWorkspaceLoggerUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/logger/client.go b/resource-manager/apimanagement/2024-05-01/logger/client.go new file mode 100644 index 00000000000..c7b58012a84 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/client.go @@ -0,0 +1,26 @@ +package logger + +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 LoggerClient struct { + Client *resourcemanager.Client +} + +func NewLoggerClientWithBaseURI(sdkApi sdkEnv.Api) (*LoggerClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "logger", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating LoggerClient: %+v", err) + } + + return &LoggerClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/constants.go b/resource-manager/apimanagement/2024-05-01/logger/constants.go new file mode 100644 index 00000000000..0aa7cb68a3e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/constants.go @@ -0,0 +1,54 @@ +package logger + +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 LoggerType string + +const ( + LoggerTypeApplicationInsights LoggerType = "applicationInsights" + LoggerTypeAzureEventHub LoggerType = "azureEventHub" + LoggerTypeAzureMonitor LoggerType = "azureMonitor" +) + +func PossibleValuesForLoggerType() []string { + return []string{ + string(LoggerTypeApplicationInsights), + string(LoggerTypeAzureEventHub), + string(LoggerTypeAzureMonitor), + } +} + +func (s *LoggerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLoggerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLoggerType(input string) (*LoggerType, error) { + vals := map[string]LoggerType{ + "applicationinsights": LoggerTypeApplicationInsights, + "azureeventhub": LoggerTypeAzureEventHub, + "azuremonitor": LoggerTypeAzureMonitor, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LoggerType(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/id_logger.go b/resource-manager/apimanagement/2024-05-01/logger/id_logger.go new file mode 100644 index 00000000000..ebf285cefca --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/id_logger.go @@ -0,0 +1,139 @@ +package logger + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LoggerId{}) +} + +var _ resourceids.ResourceId = &LoggerId{} + +// LoggerId is a struct representing the Resource ID for a Logger +type LoggerId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + LoggerId string +} + +// NewLoggerID returns a new LoggerId struct +func NewLoggerID(subscriptionId string, resourceGroupName string, serviceName string, loggerId string) LoggerId { + return LoggerId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + LoggerId: loggerId, + } +} + +// ParseLoggerID parses 'input' into a LoggerId +func ParseLoggerID(input string) (*LoggerId, error) { + parser := resourceids.NewParserFromResourceIdType(&LoggerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LoggerId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLoggerIDInsensitively parses 'input' case-insensitively into a LoggerId +// note: this method should only be used for API response data and not user input +func ParseLoggerIDInsensitively(input string) (*LoggerId, error) { + parser := resourceids.NewParserFromResourceIdType(&LoggerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LoggerId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LoggerId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.LoggerId, ok = input.Parsed["loggerId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "loggerId", input) + } + + return nil +} + +// ValidateLoggerID checks that 'input' can be parsed as a Logger ID +func ValidateLoggerID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseLoggerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Logger ID +func (id LoggerId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/loggers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.LoggerId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Logger ID +func (id LoggerId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticLoggers", "loggers", "loggers"), + resourceids.UserSpecifiedSegment("loggerId", "loggerIdValue"), + } +} + +// String returns a human-readable description of this Logger ID +func (id LoggerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Logger: %q", id.LoggerId), + } + return fmt.Sprintf("Logger (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/id_logger_test.go b/resource-manager/apimanagement/2024-05-01/logger/id_logger_test.go new file mode 100644 index 00000000000..016eeaee70e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/id_logger_test.go @@ -0,0 +1,327 @@ +package logger + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &LoggerId{} + +func TestNewLoggerID(t *testing.T) { + id := NewLoggerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "loggerIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.LoggerId != "loggerIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'LoggerId'", id.LoggerId, "loggerIdValue") + } +} + +func TestFormatLoggerID(t *testing.T) { + actual := NewLoggerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "loggerIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/loggers/loggerIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLoggerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LoggerId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/loggers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/loggers/loggerIdValue", + Expected: &LoggerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + LoggerId: "loggerIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/loggers/loggerIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLoggerID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.LoggerId != v.Expected.LoggerId { + t.Fatalf("Expected %q but got %q for LoggerId", v.Expected.LoggerId, actual.LoggerId) + } + + } +} + +func TestParseLoggerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LoggerId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/loggers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/lOgGeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/loggers/loggerIdValue", + Expected: &LoggerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + LoggerId: "loggerIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/loggers/loggerIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/lOgGeRs/lOgGeRiDvAlUe", + Expected: &LoggerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + LoggerId: "lOgGeRiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/lOgGeRs/lOgGeRiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLoggerIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.LoggerId != v.Expected.LoggerId { + t.Fatalf("Expected %q but got %q for LoggerId", v.Expected.LoggerId, actual.LoggerId) + } + + } +} + +func TestSegmentsForLoggerId(t *testing.T) { + segments := LoggerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LoggerId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/id_service.go b/resource-manager/apimanagement/2024-05-01/logger/id_service.go new file mode 100644 index 00000000000..e5a5d44be9e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/id_service.go @@ -0,0 +1,130 @@ +package logger + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/id_service_test.go b/resource-manager/apimanagement/2024-05-01/logger/id_service_test.go new file mode 100644 index 00000000000..b3318f36c08 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/id_service_test.go @@ -0,0 +1,282 @@ +package logger + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/id_workspace.go b/resource-manager/apimanagement/2024-05-01/logger/id_workspace.go new file mode 100644 index 00000000000..5f3097a02c9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/id_workspace.go @@ -0,0 +1,139 @@ +package logger + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/id_workspace_test.go b/resource-manager/apimanagement/2024-05-01/logger/id_workspace_test.go new file mode 100644 index 00000000000..5e094a530d6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/id_workspace_test.go @@ -0,0 +1,327 @@ +package logger + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/id_workspacelogger.go b/resource-manager/apimanagement/2024-05-01/logger/id_workspacelogger.go new file mode 100644 index 00000000000..d4977a212e1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/id_workspacelogger.go @@ -0,0 +1,148 @@ +package logger + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceLoggerId{}) +} + +var _ resourceids.ResourceId = &WorkspaceLoggerId{} + +// WorkspaceLoggerId is a struct representing the Resource ID for a Workspace Logger +type WorkspaceLoggerId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + LoggerId string +} + +// NewWorkspaceLoggerID returns a new WorkspaceLoggerId struct +func NewWorkspaceLoggerID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, loggerId string) WorkspaceLoggerId { + return WorkspaceLoggerId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + LoggerId: loggerId, + } +} + +// ParseWorkspaceLoggerID parses 'input' into a WorkspaceLoggerId +func ParseWorkspaceLoggerID(input string) (*WorkspaceLoggerId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceLoggerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceLoggerId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceLoggerIDInsensitively parses 'input' case-insensitively into a WorkspaceLoggerId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceLoggerIDInsensitively(input string) (*WorkspaceLoggerId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceLoggerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceLoggerId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceLoggerId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.LoggerId, ok = input.Parsed["loggerId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "loggerId", input) + } + + return nil +} + +// ValidateWorkspaceLoggerID checks that 'input' can be parsed as a Workspace Logger ID +func ValidateWorkspaceLoggerID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceLoggerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Logger ID +func (id WorkspaceLoggerId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/loggers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.LoggerId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Logger ID +func (id WorkspaceLoggerId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticLoggers", "loggers", "loggers"), + resourceids.UserSpecifiedSegment("loggerId", "loggerIdValue"), + } +} + +// String returns a human-readable description of this Workspace Logger ID +func (id WorkspaceLoggerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Logger: %q", id.LoggerId), + } + return fmt.Sprintf("Workspace Logger (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/id_workspacelogger_test.go b/resource-manager/apimanagement/2024-05-01/logger/id_workspacelogger_test.go new file mode 100644 index 00000000000..61eaa9a9446 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/id_workspacelogger_test.go @@ -0,0 +1,372 @@ +package logger + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceLoggerId{} + +func TestNewWorkspaceLoggerID(t *testing.T) { + id := NewWorkspaceLoggerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "loggerIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.LoggerId != "loggerIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'LoggerId'", id.LoggerId, "loggerIdValue") + } +} + +func TestFormatWorkspaceLoggerID(t *testing.T) { + actual := NewWorkspaceLoggerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "loggerIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/loggers/loggerIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceLoggerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceLoggerId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/loggers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/loggers/loggerIdValue", + Expected: &WorkspaceLoggerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + LoggerId: "loggerIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/loggers/loggerIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceLoggerID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.LoggerId != v.Expected.LoggerId { + t.Fatalf("Expected %q but got %q for LoggerId", v.Expected.LoggerId, actual.LoggerId) + } + + } +} + +func TestParseWorkspaceLoggerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceLoggerId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/loggers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/lOgGeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/loggers/loggerIdValue", + Expected: &WorkspaceLoggerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + LoggerId: "loggerIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/loggers/loggerIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/lOgGeRs/lOgGeRiDvAlUe", + Expected: &WorkspaceLoggerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + LoggerId: "lOgGeRiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/lOgGeRs/lOgGeRiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceLoggerIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.LoggerId != v.Expected.LoggerId { + t.Fatalf("Expected %q but got %q for LoggerId", v.Expected.LoggerId, actual.LoggerId) + } + + } +} + +func TestSegmentsForWorkspaceLoggerId(t *testing.T) { + segments := WorkspaceLoggerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceLoggerId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/logger/method_createorupdate.go new file mode 100644 index 00000000000..b1a476b3cf9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/method_createorupdate.go @@ -0,0 +1,88 @@ +package logger + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *LoggerContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c LoggerClient) CreateOrUpdate(ctx context.Context, id LoggerId, input LoggerContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 LoggerContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/method_delete.go b/resource-manager/apimanagement/2024-05-01/logger/method_delete.go new file mode 100644 index 00000000000..d1edc7304d6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/method_delete.go @@ -0,0 +1,76 @@ +package logger + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c LoggerClient) Delete(ctx context.Context, id LoggerId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/method_get.go b/resource-manager/apimanagement/2024-05-01/logger/method_get.go new file mode 100644 index 00000000000..dd5216620ea --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/method_get.go @@ -0,0 +1,54 @@ +package logger + +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 *LoggerContract +} + +// Get ... +func (c LoggerClient) Get(ctx context.Context, id LoggerId) (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 LoggerContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/logger/method_getentitytag.go new file mode 100644 index 00000000000..b65f6ac22bd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/method_getentitytag.go @@ -0,0 +1,46 @@ +package logger + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c LoggerClient) GetEntityTag(ctx context.Context, id LoggerId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/logger/method_listbyservice.go new file mode 100644 index 00000000000..3765ffa1f12 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/method_listbyservice.go @@ -0,0 +1,141 @@ +package logger + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]LoggerContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []LoggerContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c LoggerClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/loggers", 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 *[]LoggerContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c LoggerClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, LoggerContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c LoggerClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate LoggerContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]LoggerContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/method_update.go b/resource-manager/apimanagement/2024-05-01/logger/method_update.go new file mode 100644 index 00000000000..e7491dd03c2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/method_update.go @@ -0,0 +1,87 @@ +package logger + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *LoggerContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c LoggerClient) Update(ctx context.Context, id LoggerId, input LoggerUpdateContract, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 LoggerContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/method_workspaceloggercreateorupdate.go b/resource-manager/apimanagement/2024-05-01/logger/method_workspaceloggercreateorupdate.go new file mode 100644 index 00000000000..d5e33e7c636 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/method_workspaceloggercreateorupdate.go @@ -0,0 +1,88 @@ +package logger + +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 WorkspaceLoggerCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *LoggerContract +} + +type WorkspaceLoggerCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceLoggerCreateOrUpdateOperationOptions() WorkspaceLoggerCreateOrUpdateOperationOptions { + return WorkspaceLoggerCreateOrUpdateOperationOptions{} +} + +func (o WorkspaceLoggerCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceLoggerCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceLoggerCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceLoggerCreateOrUpdate ... +func (c LoggerClient) WorkspaceLoggerCreateOrUpdate(ctx context.Context, id WorkspaceLoggerId, input LoggerContract, options WorkspaceLoggerCreateOrUpdateOperationOptions) (result WorkspaceLoggerCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 LoggerContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/method_workspaceloggerdelete.go b/resource-manager/apimanagement/2024-05-01/logger/method_workspaceloggerdelete.go new file mode 100644 index 00000000000..f3172071460 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/method_workspaceloggerdelete.go @@ -0,0 +1,76 @@ +package logger + +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 WorkspaceLoggerDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type WorkspaceLoggerDeleteOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceLoggerDeleteOperationOptions() WorkspaceLoggerDeleteOperationOptions { + return WorkspaceLoggerDeleteOperationOptions{} +} + +func (o WorkspaceLoggerDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceLoggerDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceLoggerDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceLoggerDelete ... +func (c LoggerClient) WorkspaceLoggerDelete(ctx context.Context, id WorkspaceLoggerId, options WorkspaceLoggerDeleteOperationOptions) (result WorkspaceLoggerDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/method_workspaceloggerget.go b/resource-manager/apimanagement/2024-05-01/logger/method_workspaceloggerget.go new file mode 100644 index 00000000000..87d1ff961bf --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/method_workspaceloggerget.go @@ -0,0 +1,54 @@ +package logger + +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 WorkspaceLoggerGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *LoggerContract +} + +// WorkspaceLoggerGet ... +func (c LoggerClient) WorkspaceLoggerGet(ctx context.Context, id WorkspaceLoggerId) (result WorkspaceLoggerGetOperationResponse, 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 LoggerContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/method_workspaceloggergetentitytag.go b/resource-manager/apimanagement/2024-05-01/logger/method_workspaceloggergetentitytag.go new file mode 100644 index 00000000000..92850b0479a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/method_workspaceloggergetentitytag.go @@ -0,0 +1,46 @@ +package logger + +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 WorkspaceLoggerGetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceLoggerGetEntityTag ... +func (c LoggerClient) WorkspaceLoggerGetEntityTag(ctx context.Context, id WorkspaceLoggerId) (result WorkspaceLoggerGetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/method_workspaceloggerlistbyworkspace.go b/resource-manager/apimanagement/2024-05-01/logger/method_workspaceloggerlistbyworkspace.go new file mode 100644 index 00000000000..e998bb677be --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/method_workspaceloggerlistbyworkspace.go @@ -0,0 +1,141 @@ +package logger + +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 WorkspaceLoggerListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]LoggerContract +} + +type WorkspaceLoggerListByWorkspaceCompleteResult struct { + LatestHttpResponse *http.Response + Items []LoggerContract +} + +type WorkspaceLoggerListByWorkspaceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultWorkspaceLoggerListByWorkspaceOperationOptions() WorkspaceLoggerListByWorkspaceOperationOptions { + return WorkspaceLoggerListByWorkspaceOperationOptions{} +} + +func (o WorkspaceLoggerListByWorkspaceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceLoggerListByWorkspaceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceLoggerListByWorkspaceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspaceLoggerListByWorkspaceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceLoggerListByWorkspaceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceLoggerListByWorkspace ... +func (c LoggerClient) WorkspaceLoggerListByWorkspace(ctx context.Context, id WorkspaceId, options WorkspaceLoggerListByWorkspaceOperationOptions) (result WorkspaceLoggerListByWorkspaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspaceLoggerListByWorkspaceCustomPager{}, + Path: fmt.Sprintf("%s/loggers", 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 *[]LoggerContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceLoggerListByWorkspaceComplete retrieves all the results into a single object +func (c LoggerClient) WorkspaceLoggerListByWorkspaceComplete(ctx context.Context, id WorkspaceId, options WorkspaceLoggerListByWorkspaceOperationOptions) (WorkspaceLoggerListByWorkspaceCompleteResult, error) { + return c.WorkspaceLoggerListByWorkspaceCompleteMatchingPredicate(ctx, id, options, LoggerContractOperationPredicate{}) +} + +// WorkspaceLoggerListByWorkspaceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c LoggerClient) WorkspaceLoggerListByWorkspaceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options WorkspaceLoggerListByWorkspaceOperationOptions, predicate LoggerContractOperationPredicate) (result WorkspaceLoggerListByWorkspaceCompleteResult, err error) { + items := make([]LoggerContract, 0) + + resp, err := c.WorkspaceLoggerListByWorkspace(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceLoggerListByWorkspaceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/method_workspaceloggerupdate.go b/resource-manager/apimanagement/2024-05-01/logger/method_workspaceloggerupdate.go new file mode 100644 index 00000000000..06106d14878 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/method_workspaceloggerupdate.go @@ -0,0 +1,87 @@ +package logger + +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 WorkspaceLoggerUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *LoggerContract +} + +type WorkspaceLoggerUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceLoggerUpdateOperationOptions() WorkspaceLoggerUpdateOperationOptions { + return WorkspaceLoggerUpdateOperationOptions{} +} + +func (o WorkspaceLoggerUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceLoggerUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceLoggerUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceLoggerUpdate ... +func (c LoggerClient) WorkspaceLoggerUpdate(ctx context.Context, id WorkspaceLoggerId, input LoggerUpdateContract, options WorkspaceLoggerUpdateOperationOptions) (result WorkspaceLoggerUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 LoggerContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/model_loggercontract.go b/resource-manager/apimanagement/2024-05-01/logger/model_loggercontract.go new file mode 100644 index 00000000000..972cc05b227 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/model_loggercontract.go @@ -0,0 +1,11 @@ +package logger + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LoggerContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *LoggerContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/model_loggercontractproperties.go b/resource-manager/apimanagement/2024-05-01/logger/model_loggercontractproperties.go new file mode 100644 index 00000000000..d70cd7607e3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/model_loggercontractproperties.go @@ -0,0 +1,12 @@ +package logger + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LoggerContractProperties struct { + Credentials *map[string]string `json:"credentials,omitempty"` + Description *string `json:"description,omitempty"` + IsBuffered *bool `json:"isBuffered,omitempty"` + LoggerType LoggerType `json:"loggerType"` + ResourceId *string `json:"resourceId,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/model_loggerupdatecontract.go b/resource-manager/apimanagement/2024-05-01/logger/model_loggerupdatecontract.go new file mode 100644 index 00000000000..35373cca5cf --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/model_loggerupdatecontract.go @@ -0,0 +1,8 @@ +package logger + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LoggerUpdateContract struct { + Properties *LoggerUpdateParameters `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/model_loggerupdateparameters.go b/resource-manager/apimanagement/2024-05-01/logger/model_loggerupdateparameters.go new file mode 100644 index 00000000000..4a4958deaf5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/model_loggerupdateparameters.go @@ -0,0 +1,11 @@ +package logger + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LoggerUpdateParameters struct { + Credentials *map[string]string `json:"credentials,omitempty"` + Description *string `json:"description,omitempty"` + IsBuffered *bool `json:"isBuffered,omitempty"` + LoggerType *LoggerType `json:"loggerType,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/logger/predicates.go b/resource-manager/apimanagement/2024-05-01/logger/predicates.go new file mode 100644 index 00000000000..9dfff89de12 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/predicates.go @@ -0,0 +1,27 @@ +package logger + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LoggerContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p LoggerContractOperationPredicate) Matches(input LoggerContract) 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/apimanagement/2024-05-01/logger/version.go b/resource-manager/apimanagement/2024-05-01/logger/version.go new file mode 100644 index 00000000000..02cfcf76bb6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/logger/version.go @@ -0,0 +1,12 @@ +package logger + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/logger/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/README.md b/resource-manager/apimanagement/2024-05-01/namedvalue/README.md new file mode 100644 index 00000000000..784d53e5afb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/README.md @@ -0,0 +1,274 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/namedvalue` Documentation + +The `namedvalue` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/namedvalue" +``` + + +### Client Initialization + +```go +client := namedvalue.NewNamedValueClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `NamedValueClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := namedvalue.NewNamedValueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "namedValueIdValue") + +payload := namedvalue.NamedValueCreateContract{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload, namedvalue.DefaultCreateOrUpdateOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `NamedValueClient.Delete` + +```go +ctx := context.TODO() +id := namedvalue.NewNamedValueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "namedValueIdValue") + +read, err := client.Delete(ctx, id, namedvalue.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NamedValueClient.Get` + +```go +ctx := context.TODO() +id := namedvalue.NewNamedValueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "namedValueIdValue") + +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: `NamedValueClient.GetEntityTag` + +```go +ctx := context.TODO() +id := namedvalue.NewNamedValueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "namedValueIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NamedValueClient.ListByService` + +```go +ctx := context.TODO() +id := namedvalue.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, namedvalue.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, namedvalue.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `NamedValueClient.ListValue` + +```go +ctx := context.TODO() +id := namedvalue.NewNamedValueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "namedValueIdValue") + +read, err := client.ListValue(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NamedValueClient.RefreshSecret` + +```go +ctx := context.TODO() +id := namedvalue.NewNamedValueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "namedValueIdValue") + +if err := client.RefreshSecretThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `NamedValueClient.Update` + +```go +ctx := context.TODO() +id := namedvalue.NewNamedValueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "namedValueIdValue") + +payload := namedvalue.NamedValueUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload, namedvalue.DefaultUpdateOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `NamedValueClient.WorkspaceNamedValueCreateOrUpdate` + +```go +ctx := context.TODO() +id := namedvalue.NewWorkspaceNamedValueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "namedValueIdValue") + +payload := namedvalue.NamedValueCreateContract{ + // ... +} + + +if err := client.WorkspaceNamedValueCreateOrUpdateThenPoll(ctx, id, payload, namedvalue.DefaultWorkspaceNamedValueCreateOrUpdateOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `NamedValueClient.WorkspaceNamedValueDelete` + +```go +ctx := context.TODO() +id := namedvalue.NewWorkspaceNamedValueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "namedValueIdValue") + +read, err := client.WorkspaceNamedValueDelete(ctx, id, namedvalue.DefaultWorkspaceNamedValueDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NamedValueClient.WorkspaceNamedValueGet` + +```go +ctx := context.TODO() +id := namedvalue.NewWorkspaceNamedValueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "namedValueIdValue") + +read, err := client.WorkspaceNamedValueGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NamedValueClient.WorkspaceNamedValueGetEntityTag` + +```go +ctx := context.TODO() +id := namedvalue.NewWorkspaceNamedValueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "namedValueIdValue") + +read, err := client.WorkspaceNamedValueGetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NamedValueClient.WorkspaceNamedValueListByService` + +```go +ctx := context.TODO() +id := namedvalue.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +// alternatively `client.WorkspaceNamedValueListByService(ctx, id, namedvalue.DefaultWorkspaceNamedValueListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.WorkspaceNamedValueListByServiceComplete(ctx, id, namedvalue.DefaultWorkspaceNamedValueListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `NamedValueClient.WorkspaceNamedValueListValue` + +```go +ctx := context.TODO() +id := namedvalue.NewWorkspaceNamedValueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "namedValueIdValue") + +read, err := client.WorkspaceNamedValueListValue(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NamedValueClient.WorkspaceNamedValueRefreshSecret` + +```go +ctx := context.TODO() +id := namedvalue.NewWorkspaceNamedValueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "namedValueIdValue") + +if err := client.WorkspaceNamedValueRefreshSecretThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `NamedValueClient.WorkspaceNamedValueUpdate` + +```go +ctx := context.TODO() +id := namedvalue.NewWorkspaceNamedValueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "namedValueIdValue") + +payload := namedvalue.NamedValueUpdateParameters{ + // ... +} + + +if err := client.WorkspaceNamedValueUpdateThenPoll(ctx, id, payload, namedvalue.DefaultWorkspaceNamedValueUpdateOperationOptions()); err != nil { + // handle the error +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/client.go b/resource-manager/apimanagement/2024-05-01/namedvalue/client.go new file mode 100644 index 00000000000..9bc64e690ca --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/client.go @@ -0,0 +1,26 @@ +package namedvalue + +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 NamedValueClient struct { + Client *resourcemanager.Client +} + +func NewNamedValueClientWithBaseURI(sdkApi sdkEnv.Api) (*NamedValueClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "namedvalue", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating NamedValueClient: %+v", err) + } + + return &NamedValueClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/constants.go b/resource-manager/apimanagement/2024-05-01/namedvalue/constants.go new file mode 100644 index 00000000000..8e3d91746b1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/constants.go @@ -0,0 +1,51 @@ +package namedvalue + +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 KeyVaultRefreshState string + +const ( + KeyVaultRefreshStateFalse KeyVaultRefreshState = "false" + KeyVaultRefreshStateTrue KeyVaultRefreshState = "true" +) + +func PossibleValuesForKeyVaultRefreshState() []string { + return []string{ + string(KeyVaultRefreshStateFalse), + string(KeyVaultRefreshStateTrue), + } +} + +func (s *KeyVaultRefreshState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKeyVaultRefreshState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseKeyVaultRefreshState(input string) (*KeyVaultRefreshState, error) { + vals := map[string]KeyVaultRefreshState{ + "false": KeyVaultRefreshStateFalse, + "true": KeyVaultRefreshStateTrue, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := KeyVaultRefreshState(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/id_namedvalue.go b/resource-manager/apimanagement/2024-05-01/namedvalue/id_namedvalue.go new file mode 100644 index 00000000000..960d341eb81 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/id_namedvalue.go @@ -0,0 +1,139 @@ +package namedvalue + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&NamedValueId{}) +} + +var _ resourceids.ResourceId = &NamedValueId{} + +// NamedValueId is a struct representing the Resource ID for a Named Value +type NamedValueId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + NamedValueId string +} + +// NewNamedValueID returns a new NamedValueId struct +func NewNamedValueID(subscriptionId string, resourceGroupName string, serviceName string, namedValueId string) NamedValueId { + return NamedValueId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + NamedValueId: namedValueId, + } +} + +// ParseNamedValueID parses 'input' into a NamedValueId +func ParseNamedValueID(input string) (*NamedValueId, error) { + parser := resourceids.NewParserFromResourceIdType(&NamedValueId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NamedValueId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNamedValueIDInsensitively parses 'input' case-insensitively into a NamedValueId +// note: this method should only be used for API response data and not user input +func ParseNamedValueIDInsensitively(input string) (*NamedValueId, error) { + parser := resourceids.NewParserFromResourceIdType(&NamedValueId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NamedValueId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NamedValueId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.NamedValueId, ok = input.Parsed["namedValueId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "namedValueId", input) + } + + return nil +} + +// ValidateNamedValueID checks that 'input' can be parsed as a Named Value ID +func ValidateNamedValueID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseNamedValueID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Named Value ID +func (id NamedValueId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/namedValues/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.NamedValueId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Named Value ID +func (id NamedValueId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticNamedValues", "namedValues", "namedValues"), + resourceids.UserSpecifiedSegment("namedValueId", "namedValueIdValue"), + } +} + +// String returns a human-readable description of this Named Value ID +func (id NamedValueId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Named Value: %q", id.NamedValueId), + } + return fmt.Sprintf("Named Value (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/id_namedvalue_test.go b/resource-manager/apimanagement/2024-05-01/namedvalue/id_namedvalue_test.go new file mode 100644 index 00000000000..66c60dd4cfb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/id_namedvalue_test.go @@ -0,0 +1,327 @@ +package namedvalue + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &NamedValueId{} + +func TestNewNamedValueID(t *testing.T) { + id := NewNamedValueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "namedValueIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.NamedValueId != "namedValueIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'NamedValueId'", id.NamedValueId, "namedValueIdValue") + } +} + +func TestFormatNamedValueID(t *testing.T) { + actual := NewNamedValueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "namedValueIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/namedValues/namedValueIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNamedValueID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NamedValueId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/namedValues", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/namedValues/namedValueIdValue", + Expected: &NamedValueId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + NamedValueId: "namedValueIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/namedValues/namedValueIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNamedValueID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.NamedValueId != v.Expected.NamedValueId { + t.Fatalf("Expected %q but got %q for NamedValueId", v.Expected.NamedValueId, actual.NamedValueId) + } + + } +} + +func TestParseNamedValueIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NamedValueId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/namedValues", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/nAmEdVaLuEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/namedValues/namedValueIdValue", + Expected: &NamedValueId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + NamedValueId: "namedValueIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/namedValues/namedValueIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/nAmEdVaLuEs/nAmEdVaLuEiDvAlUe", + Expected: &NamedValueId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + NamedValueId: "nAmEdVaLuEiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/nAmEdVaLuEs/nAmEdVaLuEiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNamedValueIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.NamedValueId != v.Expected.NamedValueId { + t.Fatalf("Expected %q but got %q for NamedValueId", v.Expected.NamedValueId, actual.NamedValueId) + } + + } +} + +func TestSegmentsForNamedValueId(t *testing.T) { + segments := NamedValueId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NamedValueId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/id_service.go b/resource-manager/apimanagement/2024-05-01/namedvalue/id_service.go new file mode 100644 index 00000000000..3e71ff3a6f0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/id_service.go @@ -0,0 +1,130 @@ +package namedvalue + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/id_service_test.go b/resource-manager/apimanagement/2024-05-01/namedvalue/id_service_test.go new file mode 100644 index 00000000000..578b3b49886 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/id_service_test.go @@ -0,0 +1,282 @@ +package namedvalue + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/id_workspace.go b/resource-manager/apimanagement/2024-05-01/namedvalue/id_workspace.go new file mode 100644 index 00000000000..7487f000469 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/id_workspace.go @@ -0,0 +1,139 @@ +package namedvalue + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/id_workspace_test.go b/resource-manager/apimanagement/2024-05-01/namedvalue/id_workspace_test.go new file mode 100644 index 00000000000..72fad5f6a23 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/id_workspace_test.go @@ -0,0 +1,327 @@ +package namedvalue + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/id_workspacenamedvalue.go b/resource-manager/apimanagement/2024-05-01/namedvalue/id_workspacenamedvalue.go new file mode 100644 index 00000000000..44f55e1b20a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/id_workspacenamedvalue.go @@ -0,0 +1,148 @@ +package namedvalue + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceNamedValueId{}) +} + +var _ resourceids.ResourceId = &WorkspaceNamedValueId{} + +// WorkspaceNamedValueId is a struct representing the Resource ID for a Workspace Named Value +type WorkspaceNamedValueId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + NamedValueId string +} + +// NewWorkspaceNamedValueID returns a new WorkspaceNamedValueId struct +func NewWorkspaceNamedValueID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, namedValueId string) WorkspaceNamedValueId { + return WorkspaceNamedValueId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + NamedValueId: namedValueId, + } +} + +// ParseWorkspaceNamedValueID parses 'input' into a WorkspaceNamedValueId +func ParseWorkspaceNamedValueID(input string) (*WorkspaceNamedValueId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceNamedValueId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceNamedValueId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceNamedValueIDInsensitively parses 'input' case-insensitively into a WorkspaceNamedValueId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceNamedValueIDInsensitively(input string) (*WorkspaceNamedValueId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceNamedValueId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceNamedValueId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceNamedValueId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.NamedValueId, ok = input.Parsed["namedValueId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "namedValueId", input) + } + + return nil +} + +// ValidateWorkspaceNamedValueID checks that 'input' can be parsed as a Workspace Named Value ID +func ValidateWorkspaceNamedValueID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceNamedValueID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Named Value ID +func (id WorkspaceNamedValueId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/namedValues/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.NamedValueId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Named Value ID +func (id WorkspaceNamedValueId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticNamedValues", "namedValues", "namedValues"), + resourceids.UserSpecifiedSegment("namedValueId", "namedValueIdValue"), + } +} + +// String returns a human-readable description of this Workspace Named Value ID +func (id WorkspaceNamedValueId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Named Value: %q", id.NamedValueId), + } + return fmt.Sprintf("Workspace Named Value (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/id_workspacenamedvalue_test.go b/resource-manager/apimanagement/2024-05-01/namedvalue/id_workspacenamedvalue_test.go new file mode 100644 index 00000000000..4264c9f0378 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/id_workspacenamedvalue_test.go @@ -0,0 +1,372 @@ +package namedvalue + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceNamedValueId{} + +func TestNewWorkspaceNamedValueID(t *testing.T) { + id := NewWorkspaceNamedValueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "namedValueIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.NamedValueId != "namedValueIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'NamedValueId'", id.NamedValueId, "namedValueIdValue") + } +} + +func TestFormatWorkspaceNamedValueID(t *testing.T) { + actual := NewWorkspaceNamedValueID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "namedValueIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/namedValues/namedValueIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceNamedValueID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceNamedValueId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/namedValues", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/namedValues/namedValueIdValue", + Expected: &WorkspaceNamedValueId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + NamedValueId: "namedValueIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/namedValues/namedValueIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceNamedValueID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.NamedValueId != v.Expected.NamedValueId { + t.Fatalf("Expected %q but got %q for NamedValueId", v.Expected.NamedValueId, actual.NamedValueId) + } + + } +} + +func TestParseWorkspaceNamedValueIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceNamedValueId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/namedValues", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/nAmEdVaLuEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/namedValues/namedValueIdValue", + Expected: &WorkspaceNamedValueId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + NamedValueId: "namedValueIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/namedValues/namedValueIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/nAmEdVaLuEs/nAmEdVaLuEiDvAlUe", + Expected: &WorkspaceNamedValueId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + NamedValueId: "nAmEdVaLuEiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/nAmEdVaLuEs/nAmEdVaLuEiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceNamedValueIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.NamedValueId != v.Expected.NamedValueId { + t.Fatalf("Expected %q but got %q for NamedValueId", v.Expected.NamedValueId, actual.NamedValueId) + } + + } +} + +func TestSegmentsForWorkspaceNamedValueId(t *testing.T) { + segments := WorkspaceNamedValueId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceNamedValueId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/namedvalue/method_createorupdate.go new file mode 100644 index 00000000000..a12111f998e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/method_createorupdate.go @@ -0,0 +1,103 @@ +package namedvalue + +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 *NamedValueContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c NamedValueClient) CreateOrUpdate(ctx context.Context, id NamedValueId, input NamedValueCreateContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 NamedValueClient) CreateOrUpdateThenPoll(ctx context.Context, id NamedValueId, input NamedValueCreateContract, options CreateOrUpdateOperationOptions) error { + result, err := c.CreateOrUpdate(ctx, id, input, options) + 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/apimanagement/2024-05-01/namedvalue/method_delete.go b/resource-manager/apimanagement/2024-05-01/namedvalue/method_delete.go new file mode 100644 index 00000000000..f47f9ad5955 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/method_delete.go @@ -0,0 +1,76 @@ +package namedvalue + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c NamedValueClient) Delete(ctx context.Context, id NamedValueId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/method_get.go b/resource-manager/apimanagement/2024-05-01/namedvalue/method_get.go new file mode 100644 index 00000000000..b4f6fc01960 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/method_get.go @@ -0,0 +1,54 @@ +package namedvalue + +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 *NamedValueContract +} + +// Get ... +func (c NamedValueClient) Get(ctx context.Context, id NamedValueId) (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 NamedValueContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/namedvalue/method_getentitytag.go new file mode 100644 index 00000000000..d292a66e0af --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/method_getentitytag.go @@ -0,0 +1,46 @@ +package namedvalue + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c NamedValueClient) GetEntityTag(ctx context.Context, id NamedValueId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/namedvalue/method_listbyservice.go new file mode 100644 index 00000000000..c484c236266 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/method_listbyservice.go @@ -0,0 +1,145 @@ +package namedvalue + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]NamedValueContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []NamedValueContract +} + +type ListByServiceOperationOptions struct { + Filter *string + IsKeyVaultRefreshFailed *bool + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.IsKeyVaultRefreshFailed != nil { + out.Append("isKeyVaultRefreshFailed", fmt.Sprintf("%v", *o.IsKeyVaultRefreshFailed)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c NamedValueClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/namedValues", 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 *[]NamedValueContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c NamedValueClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, NamedValueContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c NamedValueClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate NamedValueContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]NamedValueContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/method_listvalue.go b/resource-manager/apimanagement/2024-05-01/namedvalue/method_listvalue.go new file mode 100644 index 00000000000..80e6212cce7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/method_listvalue.go @@ -0,0 +1,55 @@ +package namedvalue + +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 ListValueOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *NamedValueSecretContract +} + +// ListValue ... +func (c NamedValueClient) ListValue(ctx context.Context, id NamedValueId) (result ListValueOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listValue", 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 NamedValueSecretContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/method_refreshsecret.go b/resource-manager/apimanagement/2024-05-01/namedvalue/method_refreshsecret.go new file mode 100644 index 00000000000..695bad8ce7f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/method_refreshsecret.go @@ -0,0 +1,71 @@ +package namedvalue + +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 RefreshSecretOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *NamedValueContract +} + +// RefreshSecret ... +func (c NamedValueClient) RefreshSecret(ctx context.Context, id NamedValueId) (result RefreshSecretOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/refreshSecret", 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 +} + +// RefreshSecretThenPoll performs RefreshSecret then polls until it's completed +func (c NamedValueClient) RefreshSecretThenPoll(ctx context.Context, id NamedValueId) error { + result, err := c.RefreshSecret(ctx, id) + if err != nil { + return fmt.Errorf("performing RefreshSecret: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after RefreshSecret: %+v", err) + } + + return nil +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/method_update.go b/resource-manager/apimanagement/2024-05-01/namedvalue/method_update.go new file mode 100644 index 00000000000..0bb9dff4811 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/method_update.go @@ -0,0 +1,103 @@ +package namedvalue + +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 *NamedValueContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c NamedValueClient) Update(ctx context.Context, id NamedValueId, input NamedValueUpdateParameters, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 NamedValueClient) UpdateThenPoll(ctx context.Context, id NamedValueId, input NamedValueUpdateParameters, options UpdateOperationOptions) error { + result, err := c.Update(ctx, id, input, options) + 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/apimanagement/2024-05-01/namedvalue/method_workspacenamedvaluecreateorupdate.go b/resource-manager/apimanagement/2024-05-01/namedvalue/method_workspacenamedvaluecreateorupdate.go new file mode 100644 index 00000000000..84290f98fbb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/method_workspacenamedvaluecreateorupdate.go @@ -0,0 +1,103 @@ +package namedvalue + +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 WorkspaceNamedValueCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *NamedValueContract +} + +type WorkspaceNamedValueCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceNamedValueCreateOrUpdateOperationOptions() WorkspaceNamedValueCreateOrUpdateOperationOptions { + return WorkspaceNamedValueCreateOrUpdateOperationOptions{} +} + +func (o WorkspaceNamedValueCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceNamedValueCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceNamedValueCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceNamedValueCreateOrUpdate ... +func (c NamedValueClient) WorkspaceNamedValueCreateOrUpdate(ctx context.Context, id WorkspaceNamedValueId, input NamedValueCreateContract, options WorkspaceNamedValueCreateOrUpdateOperationOptions) (result WorkspaceNamedValueCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 +} + +// WorkspaceNamedValueCreateOrUpdateThenPoll performs WorkspaceNamedValueCreateOrUpdate then polls until it's completed +func (c NamedValueClient) WorkspaceNamedValueCreateOrUpdateThenPoll(ctx context.Context, id WorkspaceNamedValueId, input NamedValueCreateContract, options WorkspaceNamedValueCreateOrUpdateOperationOptions) error { + result, err := c.WorkspaceNamedValueCreateOrUpdate(ctx, id, input, options) + if err != nil { + return fmt.Errorf("performing WorkspaceNamedValueCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after WorkspaceNamedValueCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/method_workspacenamedvaluedelete.go b/resource-manager/apimanagement/2024-05-01/namedvalue/method_workspacenamedvaluedelete.go new file mode 100644 index 00000000000..7d05e234c48 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/method_workspacenamedvaluedelete.go @@ -0,0 +1,76 @@ +package namedvalue + +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 WorkspaceNamedValueDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type WorkspaceNamedValueDeleteOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceNamedValueDeleteOperationOptions() WorkspaceNamedValueDeleteOperationOptions { + return WorkspaceNamedValueDeleteOperationOptions{} +} + +func (o WorkspaceNamedValueDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceNamedValueDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceNamedValueDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceNamedValueDelete ... +func (c NamedValueClient) WorkspaceNamedValueDelete(ctx context.Context, id WorkspaceNamedValueId, options WorkspaceNamedValueDeleteOperationOptions) (result WorkspaceNamedValueDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/method_workspacenamedvalueget.go b/resource-manager/apimanagement/2024-05-01/namedvalue/method_workspacenamedvalueget.go new file mode 100644 index 00000000000..fd48731656e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/method_workspacenamedvalueget.go @@ -0,0 +1,54 @@ +package namedvalue + +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 WorkspaceNamedValueGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *NamedValueContract +} + +// WorkspaceNamedValueGet ... +func (c NamedValueClient) WorkspaceNamedValueGet(ctx context.Context, id WorkspaceNamedValueId) (result WorkspaceNamedValueGetOperationResponse, 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 NamedValueContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/method_workspacenamedvaluegetentitytag.go b/resource-manager/apimanagement/2024-05-01/namedvalue/method_workspacenamedvaluegetentitytag.go new file mode 100644 index 00000000000..f1b4ee37389 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/method_workspacenamedvaluegetentitytag.go @@ -0,0 +1,46 @@ +package namedvalue + +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 WorkspaceNamedValueGetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceNamedValueGetEntityTag ... +func (c NamedValueClient) WorkspaceNamedValueGetEntityTag(ctx context.Context, id WorkspaceNamedValueId) (result WorkspaceNamedValueGetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/method_workspacenamedvaluelistbyservice.go b/resource-manager/apimanagement/2024-05-01/namedvalue/method_workspacenamedvaluelistbyservice.go new file mode 100644 index 00000000000..87a17e3f92f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/method_workspacenamedvaluelistbyservice.go @@ -0,0 +1,145 @@ +package namedvalue + +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 WorkspaceNamedValueListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]NamedValueContract +} + +type WorkspaceNamedValueListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []NamedValueContract +} + +type WorkspaceNamedValueListByServiceOperationOptions struct { + Filter *string + IsKeyVaultRefreshFailed *KeyVaultRefreshState + Skip *int64 + Top *int64 +} + +func DefaultWorkspaceNamedValueListByServiceOperationOptions() WorkspaceNamedValueListByServiceOperationOptions { + return WorkspaceNamedValueListByServiceOperationOptions{} +} + +func (o WorkspaceNamedValueListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceNamedValueListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceNamedValueListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.IsKeyVaultRefreshFailed != nil { + out.Append("isKeyVaultRefreshFailed", fmt.Sprintf("%v", *o.IsKeyVaultRefreshFailed)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspaceNamedValueListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceNamedValueListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceNamedValueListByService ... +func (c NamedValueClient) WorkspaceNamedValueListByService(ctx context.Context, id WorkspaceId, options WorkspaceNamedValueListByServiceOperationOptions) (result WorkspaceNamedValueListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspaceNamedValueListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/namedValues", 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 *[]NamedValueContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceNamedValueListByServiceComplete retrieves all the results into a single object +func (c NamedValueClient) WorkspaceNamedValueListByServiceComplete(ctx context.Context, id WorkspaceId, options WorkspaceNamedValueListByServiceOperationOptions) (WorkspaceNamedValueListByServiceCompleteResult, error) { + return c.WorkspaceNamedValueListByServiceCompleteMatchingPredicate(ctx, id, options, NamedValueContractOperationPredicate{}) +} + +// WorkspaceNamedValueListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c NamedValueClient) WorkspaceNamedValueListByServiceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options WorkspaceNamedValueListByServiceOperationOptions, predicate NamedValueContractOperationPredicate) (result WorkspaceNamedValueListByServiceCompleteResult, err error) { + items := make([]NamedValueContract, 0) + + resp, err := c.WorkspaceNamedValueListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceNamedValueListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/method_workspacenamedvaluelistvalue.go b/resource-manager/apimanagement/2024-05-01/namedvalue/method_workspacenamedvaluelistvalue.go new file mode 100644 index 00000000000..ced0d6c1600 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/method_workspacenamedvaluelistvalue.go @@ -0,0 +1,55 @@ +package namedvalue + +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 WorkspaceNamedValueListValueOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *NamedValueSecretContract +} + +// WorkspaceNamedValueListValue ... +func (c NamedValueClient) WorkspaceNamedValueListValue(ctx context.Context, id WorkspaceNamedValueId) (result WorkspaceNamedValueListValueOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listValue", 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 NamedValueSecretContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/method_workspacenamedvaluerefreshsecret.go b/resource-manager/apimanagement/2024-05-01/namedvalue/method_workspacenamedvaluerefreshsecret.go new file mode 100644 index 00000000000..a5b0c11b0dc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/method_workspacenamedvaluerefreshsecret.go @@ -0,0 +1,71 @@ +package namedvalue + +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 WorkspaceNamedValueRefreshSecretOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *NamedValueContract +} + +// WorkspaceNamedValueRefreshSecret ... +func (c NamedValueClient) WorkspaceNamedValueRefreshSecret(ctx context.Context, id WorkspaceNamedValueId) (result WorkspaceNamedValueRefreshSecretOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/refreshSecret", 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 +} + +// WorkspaceNamedValueRefreshSecretThenPoll performs WorkspaceNamedValueRefreshSecret then polls until it's completed +func (c NamedValueClient) WorkspaceNamedValueRefreshSecretThenPoll(ctx context.Context, id WorkspaceNamedValueId) error { + result, err := c.WorkspaceNamedValueRefreshSecret(ctx, id) + if err != nil { + return fmt.Errorf("performing WorkspaceNamedValueRefreshSecret: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after WorkspaceNamedValueRefreshSecret: %+v", err) + } + + return nil +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/method_workspacenamedvalueupdate.go b/resource-manager/apimanagement/2024-05-01/namedvalue/method_workspacenamedvalueupdate.go new file mode 100644 index 00000000000..2767761302a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/method_workspacenamedvalueupdate.go @@ -0,0 +1,103 @@ +package namedvalue + +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 WorkspaceNamedValueUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *NamedValueContract +} + +type WorkspaceNamedValueUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceNamedValueUpdateOperationOptions() WorkspaceNamedValueUpdateOperationOptions { + return WorkspaceNamedValueUpdateOperationOptions{} +} + +func (o WorkspaceNamedValueUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceNamedValueUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceNamedValueUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceNamedValueUpdate ... +func (c NamedValueClient) WorkspaceNamedValueUpdate(ctx context.Context, id WorkspaceNamedValueId, input NamedValueUpdateParameters, options WorkspaceNamedValueUpdateOperationOptions) (result WorkspaceNamedValueUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 +} + +// WorkspaceNamedValueUpdateThenPoll performs WorkspaceNamedValueUpdate then polls until it's completed +func (c NamedValueClient) WorkspaceNamedValueUpdateThenPoll(ctx context.Context, id WorkspaceNamedValueId, input NamedValueUpdateParameters, options WorkspaceNamedValueUpdateOperationOptions) error { + result, err := c.WorkspaceNamedValueUpdate(ctx, id, input, options) + if err != nil { + return fmt.Errorf("performing WorkspaceNamedValueUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after WorkspaceNamedValueUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/model_keyvaultcontractcreateproperties.go b/resource-manager/apimanagement/2024-05-01/namedvalue/model_keyvaultcontractcreateproperties.go new file mode 100644 index 00000000000..7c21d4ced86 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/model_keyvaultcontractcreateproperties.go @@ -0,0 +1,9 @@ +package namedvalue + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyVaultContractCreateProperties struct { + IdentityClientId *string `json:"identityClientId,omitempty"` + SecretIdentifier *string `json:"secretIdentifier,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/model_keyvaultcontractproperties.go b/resource-manager/apimanagement/2024-05-01/namedvalue/model_keyvaultcontractproperties.go new file mode 100644 index 00000000000..9f8d5ec6e0c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/model_keyvaultcontractproperties.go @@ -0,0 +1,10 @@ +package namedvalue + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyVaultContractProperties struct { + IdentityClientId *string `json:"identityClientId,omitempty"` + LastStatus *KeyVaultLastAccessStatusContractProperties `json:"lastStatus,omitempty"` + SecretIdentifier *string `json:"secretIdentifier,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/model_keyvaultlastaccessstatuscontractproperties.go b/resource-manager/apimanagement/2024-05-01/namedvalue/model_keyvaultlastaccessstatuscontractproperties.go new file mode 100644 index 00000000000..a27c207308c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/model_keyvaultlastaccessstatuscontractproperties.go @@ -0,0 +1,28 @@ +package namedvalue + +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 KeyVaultLastAccessStatusContractProperties struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` + TimeStampUtc *string `json:"timeStampUtc,omitempty"` +} + +func (o *KeyVaultLastAccessStatusContractProperties) GetTimeStampUtcAsTime() (*time.Time, error) { + if o.TimeStampUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.TimeStampUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *KeyVaultLastAccessStatusContractProperties) SetTimeStampUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.TimeStampUtc = &formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/model_namedvaluecontract.go b/resource-manager/apimanagement/2024-05-01/namedvalue/model_namedvaluecontract.go new file mode 100644 index 00000000000..bfaa27c0bc2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/model_namedvaluecontract.go @@ -0,0 +1,11 @@ +package namedvalue + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NamedValueContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *NamedValueContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/model_namedvaluecontractproperties.go b/resource-manager/apimanagement/2024-05-01/namedvalue/model_namedvaluecontractproperties.go new file mode 100644 index 00000000000..ebfa7e5d22f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/model_namedvaluecontractproperties.go @@ -0,0 +1,13 @@ +package namedvalue + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NamedValueContractProperties struct { + DisplayName string `json:"displayName"` + KeyVault *KeyVaultContractProperties `json:"keyVault,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + Secret *bool `json:"secret,omitempty"` + Tags *[]string `json:"tags,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/model_namedvaluecreatecontract.go b/resource-manager/apimanagement/2024-05-01/namedvalue/model_namedvaluecreatecontract.go new file mode 100644 index 00000000000..5446f9b8985 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/model_namedvaluecreatecontract.go @@ -0,0 +1,11 @@ +package namedvalue + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NamedValueCreateContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *NamedValueCreateContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/model_namedvaluecreatecontractproperties.go b/resource-manager/apimanagement/2024-05-01/namedvalue/model_namedvaluecreatecontractproperties.go new file mode 100644 index 00000000000..2be31c2662f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/model_namedvaluecreatecontractproperties.go @@ -0,0 +1,12 @@ +package namedvalue + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NamedValueCreateContractProperties struct { + DisplayName string `json:"displayName"` + KeyVault *KeyVaultContractCreateProperties `json:"keyVault,omitempty"` + Secret *bool `json:"secret,omitempty"` + Tags *[]string `json:"tags,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/model_namedvaluesecretcontract.go b/resource-manager/apimanagement/2024-05-01/namedvalue/model_namedvaluesecretcontract.go new file mode 100644 index 00000000000..94b2c5c2982 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/model_namedvaluesecretcontract.go @@ -0,0 +1,8 @@ +package namedvalue + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NamedValueSecretContract struct { + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/model_namedvalueupdateparameterproperties.go b/resource-manager/apimanagement/2024-05-01/namedvalue/model_namedvalueupdateparameterproperties.go new file mode 100644 index 00000000000..1aeaf47e26c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/model_namedvalueupdateparameterproperties.go @@ -0,0 +1,12 @@ +package namedvalue + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NamedValueUpdateParameterProperties struct { + DisplayName *string `json:"displayName,omitempty"` + KeyVault *KeyVaultContractCreateProperties `json:"keyVault,omitempty"` + Secret *bool `json:"secret,omitempty"` + Tags *[]string `json:"tags,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/model_namedvalueupdateparameters.go b/resource-manager/apimanagement/2024-05-01/namedvalue/model_namedvalueupdateparameters.go new file mode 100644 index 00000000000..1b480e40657 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/model_namedvalueupdateparameters.go @@ -0,0 +1,8 @@ +package namedvalue + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NamedValueUpdateParameters struct { + Properties *NamedValueUpdateParameterProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/namedvalue/predicates.go b/resource-manager/apimanagement/2024-05-01/namedvalue/predicates.go new file mode 100644 index 00000000000..7bffc82f9da --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/predicates.go @@ -0,0 +1,27 @@ +package namedvalue + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NamedValueContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p NamedValueContractOperationPredicate) Matches(input NamedValueContract) 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/apimanagement/2024-05-01/namedvalue/version.go b/resource-manager/apimanagement/2024-05-01/namedvalue/version.go new file mode 100644 index 00000000000..225a44fecca --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/namedvalue/version.go @@ -0,0 +1,12 @@ +package namedvalue + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/namedvalue/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/networkstatus/README.md b/resource-manager/apimanagement/2024-05-01/networkstatus/README.md new file mode 100644 index 00000000000..0f4721b9786 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/networkstatus/README.md @@ -0,0 +1,52 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/networkstatus` Documentation + +The `networkstatus` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/networkstatus" +``` + + +### Client Initialization + +```go +client := networkstatus.NewNetworkStatusClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `NetworkStatusClient.ListByLocation` + +```go +ctx := context.TODO() +id := networkstatus.NewLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "locationValue") + +read, err := client.ListByLocation(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NetworkStatusClient.ListByService` + +```go +ctx := context.TODO() +id := networkstatus.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +read, err := client.ListByService(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/apimanagement/2024-05-01/networkstatus/client.go b/resource-manager/apimanagement/2024-05-01/networkstatus/client.go new file mode 100644 index 00000000000..a31324aaa99 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/networkstatus/client.go @@ -0,0 +1,26 @@ +package networkstatus + +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 NetworkStatusClient struct { + Client *resourcemanager.Client +} + +func NewNetworkStatusClientWithBaseURI(sdkApi sdkEnv.Api) (*NetworkStatusClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "networkstatus", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating NetworkStatusClient: %+v", err) + } + + return &NetworkStatusClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/networkstatus/constants.go b/resource-manager/apimanagement/2024-05-01/networkstatus/constants.go new file mode 100644 index 00000000000..caf05ed6a2c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/networkstatus/constants.go @@ -0,0 +1,54 @@ +package networkstatus + +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 ConnectivityStatusType string + +const ( + ConnectivityStatusTypeFailure ConnectivityStatusType = "failure" + ConnectivityStatusTypeInitializing ConnectivityStatusType = "initializing" + ConnectivityStatusTypeSuccess ConnectivityStatusType = "success" +) + +func PossibleValuesForConnectivityStatusType() []string { + return []string{ + string(ConnectivityStatusTypeFailure), + string(ConnectivityStatusTypeInitializing), + string(ConnectivityStatusTypeSuccess), + } +} + +func (s *ConnectivityStatusType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConnectivityStatusType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseConnectivityStatusType(input string) (*ConnectivityStatusType, error) { + vals := map[string]ConnectivityStatusType{ + "failure": ConnectivityStatusTypeFailure, + "initializing": ConnectivityStatusTypeInitializing, + "success": ConnectivityStatusTypeSuccess, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConnectivityStatusType(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/networkstatus/id_location.go b/resource-manager/apimanagement/2024-05-01/networkstatus/id_location.go new file mode 100644 index 00000000000..33d1e89e60c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/networkstatus/id_location.go @@ -0,0 +1,139 @@ +package networkstatus + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LocationId{}) +} + +var _ resourceids.ResourceId = &LocationId{} + +// LocationId is a struct representing the Resource ID for a Location +type LocationId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + LocationName string +} + +// NewLocationID returns a new LocationId struct +func NewLocationID(subscriptionId string, resourceGroupName string, serviceName string, locationName string) LocationId { + return LocationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + 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.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", 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/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, 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("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + 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("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/networkstatus/id_location_test.go b/resource-manager/apimanagement/2024-05-01/networkstatus/id_location_test.go new file mode 100644 index 00000000000..a5ca95af9fc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/networkstatus/id_location_test.go @@ -0,0 +1,327 @@ +package networkstatus + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (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", "example-resource-group", "serviceValue", "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.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + 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", "example-resource-group", "serviceValue", "locationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/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/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/locations/locationValue", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/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.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + 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/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/locations/locationValue", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/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.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/lOcAtIoNs/lOcAtIoNvAlUe", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + 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.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/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.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + 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/apimanagement/2024-05-01/networkstatus/id_service.go b/resource-manager/apimanagement/2024-05-01/networkstatus/id_service.go new file mode 100644 index 00000000000..16676b5b068 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/networkstatus/id_service.go @@ -0,0 +1,130 @@ +package networkstatus + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/networkstatus/id_service_test.go b/resource-manager/apimanagement/2024-05-01/networkstatus/id_service_test.go new file mode 100644 index 00000000000..ed1b837925a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/networkstatus/id_service_test.go @@ -0,0 +1,282 @@ +package networkstatus + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/networkstatus/method_listbylocation.go b/resource-manager/apimanagement/2024-05-01/networkstatus/method_listbylocation.go new file mode 100644 index 00000000000..2ac16a461cc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/networkstatus/method_listbylocation.go @@ -0,0 +1,55 @@ +package networkstatus + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByLocationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *NetworkStatusContract +} + +// ListByLocation ... +func (c NetworkStatusClient) ListByLocation(ctx context.Context, id LocationId) (result ListByLocationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/networkstatus", 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 NetworkStatusContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/networkstatus/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/networkstatus/method_listbyservice.go new file mode 100644 index 00000000000..82df8dfdf78 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/networkstatus/method_listbyservice.go @@ -0,0 +1,55 @@ +package networkstatus + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]NetworkStatusContractByLocation +} + +// ListByService ... +func (c NetworkStatusClient) ListByService(ctx context.Context, id ServiceId) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/networkstatus", 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 []NetworkStatusContractByLocation + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/networkstatus/model_connectivitystatuscontract.go b/resource-manager/apimanagement/2024-05-01/networkstatus/model_connectivitystatuscontract.go new file mode 100644 index 00000000000..086351f94bb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/networkstatus/model_connectivitystatuscontract.go @@ -0,0 +1,38 @@ +package networkstatus + +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 ConnectivityStatusContract struct { + Error *string `json:"error,omitempty"` + IsOptional bool `json:"isOptional"` + LastStatusChange string `json:"lastStatusChange"` + LastUpdated string `json:"lastUpdated"` + Name string `json:"name"` + ResourceType string `json:"resourceType"` + Status ConnectivityStatusType `json:"status"` +} + +func (o *ConnectivityStatusContract) GetLastStatusChangeAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.LastStatusChange, "2006-01-02T15:04:05Z07:00") +} + +func (o *ConnectivityStatusContract) SetLastStatusChangeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastStatusChange = formatted +} + +func (o *ConnectivityStatusContract) GetLastUpdatedAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.LastUpdated, "2006-01-02T15:04:05Z07:00") +} + +func (o *ConnectivityStatusContract) SetLastUpdatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdated = formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/networkstatus/model_networkstatuscontract.go b/resource-manager/apimanagement/2024-05-01/networkstatus/model_networkstatuscontract.go new file mode 100644 index 00000000000..d337b629ecf --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/networkstatus/model_networkstatuscontract.go @@ -0,0 +1,9 @@ +package networkstatus + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkStatusContract struct { + ConnectivityStatus []ConnectivityStatusContract `json:"connectivityStatus"` + DnsServers []string `json:"dnsServers"` +} diff --git a/resource-manager/apimanagement/2024-05-01/networkstatus/model_networkstatuscontractbylocation.go b/resource-manager/apimanagement/2024-05-01/networkstatus/model_networkstatuscontractbylocation.go new file mode 100644 index 00000000000..8dfdd07e0f2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/networkstatus/model_networkstatuscontractbylocation.go @@ -0,0 +1,9 @@ +package networkstatus + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkStatusContractByLocation struct { + Location *string `json:"location,omitempty"` + NetworkStatus *NetworkStatusContract `json:"networkStatus,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/networkstatus/version.go b/resource-manager/apimanagement/2024-05-01/networkstatus/version.go new file mode 100644 index 00000000000..1f21b108b50 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/networkstatus/version.go @@ -0,0 +1,12 @@ +package networkstatus + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/networkstatus/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/notification/README.md b/resource-manager/apimanagement/2024-05-01/notification/README.md new file mode 100644 index 00000000000..e2946aa5896 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notification/README.md @@ -0,0 +1,118 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/notification` Documentation + +The `notification` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/notification" +``` + + +### Client Initialization + +```go +client := notification.NewNotificationClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `NotificationClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := notification.NewNotificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "AccountClosedPublisher") + +read, err := client.CreateOrUpdate(ctx, id, notification.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NotificationClient.Get` + +```go +ctx := context.TODO() +id := notification.NewNotificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "AccountClosedPublisher") + +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: `NotificationClient.ListByService` + +```go +ctx := context.TODO() +id := notification.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, notification.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, notification.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `NotificationClient.WorkspaceNotificationCreateOrUpdate` + +```go +ctx := context.TODO() +id := notification.NewNotificationNotificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "AccountClosedPublisher") + +read, err := client.WorkspaceNotificationCreateOrUpdate(ctx, id, notification.DefaultWorkspaceNotificationCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NotificationClient.WorkspaceNotificationGet` + +```go +ctx := context.TODO() +id := notification.NewNotificationNotificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "AccountClosedPublisher") + +read, err := client.WorkspaceNotificationGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NotificationClient.WorkspaceNotificationListByService` + +```go +ctx := context.TODO() +id := notification.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +// alternatively `client.WorkspaceNotificationListByService(ctx, id, notification.DefaultWorkspaceNotificationListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.WorkspaceNotificationListByServiceComplete(ctx, id, notification.DefaultWorkspaceNotificationListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/notification/client.go b/resource-manager/apimanagement/2024-05-01/notification/client.go new file mode 100644 index 00000000000..277470faa23 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notification/client.go @@ -0,0 +1,26 @@ +package notification + +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 NotificationClient struct { + Client *resourcemanager.Client +} + +func NewNotificationClientWithBaseURI(sdkApi sdkEnv.Api) (*NotificationClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "notification", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating NotificationClient: %+v", err) + } + + return &NotificationClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/notification/constants.go b/resource-manager/apimanagement/2024-05-01/notification/constants.go new file mode 100644 index 00000000000..28634a3bb8e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notification/constants.go @@ -0,0 +1,66 @@ +package notification + +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 NotificationName string + +const ( + NotificationNameAccountClosedPublisher NotificationName = "AccountClosedPublisher" + NotificationNameBCC NotificationName = "BCC" + NotificationNameNewApplicationNotificationMessage NotificationName = "NewApplicationNotificationMessage" + NotificationNameNewIssuePublisherNotificationMessage NotificationName = "NewIssuePublisherNotificationMessage" + NotificationNamePurchasePublisherNotificationMessage NotificationName = "PurchasePublisherNotificationMessage" + NotificationNameQuotaLimitApproachingPublisherNotificationMessage NotificationName = "QuotaLimitApproachingPublisherNotificationMessage" + NotificationNameRequestPublisherNotificationMessage NotificationName = "RequestPublisherNotificationMessage" +) + +func PossibleValuesForNotificationName() []string { + return []string{ + string(NotificationNameAccountClosedPublisher), + string(NotificationNameBCC), + string(NotificationNameNewApplicationNotificationMessage), + string(NotificationNameNewIssuePublisherNotificationMessage), + string(NotificationNamePurchasePublisherNotificationMessage), + string(NotificationNameQuotaLimitApproachingPublisherNotificationMessage), + string(NotificationNameRequestPublisherNotificationMessage), + } +} + +func (s *NotificationName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseNotificationName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseNotificationName(input string) (*NotificationName, error) { + vals := map[string]NotificationName{ + "accountclosedpublisher": NotificationNameAccountClosedPublisher, + "bcc": NotificationNameBCC, + "newapplicationnotificationmessage": NotificationNameNewApplicationNotificationMessage, + "newissuepublishernotificationmessage": NotificationNameNewIssuePublisherNotificationMessage, + "purchasepublishernotificationmessage": NotificationNamePurchasePublisherNotificationMessage, + "quotalimitapproachingpublishernotificationmessage": NotificationNameQuotaLimitApproachingPublisherNotificationMessage, + "requestpublishernotificationmessage": NotificationNameRequestPublisherNotificationMessage, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NotificationName(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/notification/id_notification.go b/resource-manager/apimanagement/2024-05-01/notification/id_notification.go new file mode 100644 index 00000000000..39c82639f30 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notification/id_notification.go @@ -0,0 +1,147 @@ +package notification + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&NotificationId{}) +} + +var _ resourceids.ResourceId = &NotificationId{} + +// NotificationId is a struct representing the Resource ID for a Notification +type NotificationId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + NotificationName NotificationName +} + +// NewNotificationID returns a new NotificationId struct +func NewNotificationID(subscriptionId string, resourceGroupName string, serviceName string, notificationName NotificationName) NotificationId { + return NotificationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + NotificationName: notificationName, + } +} + +// ParseNotificationID parses 'input' into a NotificationId +func ParseNotificationID(input string) (*NotificationId, error) { + parser := resourceids.NewParserFromResourceIdType(&NotificationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NotificationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNotificationIDInsensitively parses 'input' case-insensitively into a NotificationId +// note: this method should only be used for API response data and not user input +func ParseNotificationIDInsensitively(input string) (*NotificationId, error) { + parser := resourceids.NewParserFromResourceIdType(&NotificationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NotificationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NotificationId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if v, ok := input.Parsed["notificationName"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "notificationName", input) + } + + notificationName, err := parseNotificationName(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.NotificationName = *notificationName + } + + return nil +} + +// ValidateNotificationID checks that 'input' can be parsed as a Notification ID +func ValidateNotificationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseNotificationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Notification ID +func (id NotificationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/notifications/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, string(id.NotificationName)) +} + +// Segments returns a slice of Resource ID Segments which comprise this Notification ID +func (id NotificationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticNotifications", "notifications", "notifications"), + resourceids.ConstantSegment("notificationName", PossibleValuesForNotificationName(), "AccountClosedPublisher"), + } +} + +// String returns a human-readable description of this Notification ID +func (id NotificationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Notification Name: %q", string(id.NotificationName)), + } + return fmt.Sprintf("Notification (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/notification/id_notification_test.go b/resource-manager/apimanagement/2024-05-01/notification/id_notification_test.go new file mode 100644 index 00000000000..81090054090 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notification/id_notification_test.go @@ -0,0 +1,327 @@ +package notification + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &NotificationId{} + +func TestNewNotificationID(t *testing.T) { + id := NewNotificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "AccountClosedPublisher") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.NotificationName != "AccountClosedPublisher" { + t.Fatalf("Expected %q but got %q for Segment 'NotificationName'", id.NotificationName, "AccountClosedPublisher") + } +} + +func TestFormatNotificationID(t *testing.T) { + actual := NewNotificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "AccountClosedPublisher").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNotificationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NotificationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher", + Expected: &NotificationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + NotificationName: "AccountClosedPublisher", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNotificationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.NotificationName != v.Expected.NotificationName { + t.Fatalf("Expected %q but got %q for NotificationName", v.Expected.NotificationName, actual.NotificationName) + } + + } +} + +func TestParseNotificationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NotificationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/nOtIfIcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher", + Expected: &NotificationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + NotificationName: "AccountClosedPublisher", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR", + Expected: &NotificationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + NotificationName: "AccountClosedPublisher", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNotificationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.NotificationName != v.Expected.NotificationName { + t.Fatalf("Expected %q but got %q for NotificationName", v.Expected.NotificationName, actual.NotificationName) + } + + } +} + +func TestSegmentsForNotificationId(t *testing.T) { + segments := NotificationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NotificationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/notification/id_notificationnotification.go b/resource-manager/apimanagement/2024-05-01/notification/id_notificationnotification.go new file mode 100644 index 00000000000..9d5be1827b8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notification/id_notificationnotification.go @@ -0,0 +1,156 @@ +package notification + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&NotificationNotificationId{}) +} + +var _ resourceids.ResourceId = &NotificationNotificationId{} + +// NotificationNotificationId is a struct representing the Resource ID for a Notification Notification +type NotificationNotificationId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + NotificationName NotificationName +} + +// NewNotificationNotificationID returns a new NotificationNotificationId struct +func NewNotificationNotificationID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, notificationName NotificationName) NotificationNotificationId { + return NotificationNotificationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + NotificationName: notificationName, + } +} + +// ParseNotificationNotificationID parses 'input' into a NotificationNotificationId +func ParseNotificationNotificationID(input string) (*NotificationNotificationId, error) { + parser := resourceids.NewParserFromResourceIdType(&NotificationNotificationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NotificationNotificationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNotificationNotificationIDInsensitively parses 'input' case-insensitively into a NotificationNotificationId +// note: this method should only be used for API response data and not user input +func ParseNotificationNotificationIDInsensitively(input string) (*NotificationNotificationId, error) { + parser := resourceids.NewParserFromResourceIdType(&NotificationNotificationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NotificationNotificationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NotificationNotificationId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if v, ok := input.Parsed["notificationName"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "notificationName", input) + } + + notificationName, err := parseNotificationName(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.NotificationName = *notificationName + } + + return nil +} + +// ValidateNotificationNotificationID checks that 'input' can be parsed as a Notification Notification ID +func ValidateNotificationNotificationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseNotificationNotificationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Notification Notification ID +func (id NotificationNotificationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/notifications/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, string(id.NotificationName)) +} + +// Segments returns a slice of Resource ID Segments which comprise this Notification Notification ID +func (id NotificationNotificationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticNotifications", "notifications", "notifications"), + resourceids.ConstantSegment("notificationName", PossibleValuesForNotificationName(), "AccountClosedPublisher"), + } +} + +// String returns a human-readable description of this Notification Notification ID +func (id NotificationNotificationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Notification Name: %q", string(id.NotificationName)), + } + return fmt.Sprintf("Notification Notification (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/notification/id_notificationnotification_test.go b/resource-manager/apimanagement/2024-05-01/notification/id_notificationnotification_test.go new file mode 100644 index 00000000000..6de4ee55032 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notification/id_notificationnotification_test.go @@ -0,0 +1,372 @@ +package notification + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &NotificationNotificationId{} + +func TestNewNotificationNotificationID(t *testing.T) { + id := NewNotificationNotificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "AccountClosedPublisher") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.NotificationName != "AccountClosedPublisher" { + t.Fatalf("Expected %q but got %q for Segment 'NotificationName'", id.NotificationName, "AccountClosedPublisher") + } +} + +func TestFormatNotificationNotificationID(t *testing.T) { + actual := NewNotificationNotificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "AccountClosedPublisher").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNotificationNotificationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NotificationNotificationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher", + Expected: &NotificationNotificationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + NotificationName: "AccountClosedPublisher", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNotificationNotificationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.NotificationName != v.Expected.NotificationName { + t.Fatalf("Expected %q but got %q for NotificationName", v.Expected.NotificationName, actual.NotificationName) + } + + } +} + +func TestParseNotificationNotificationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NotificationNotificationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/nOtIfIcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher", + Expected: &NotificationNotificationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + NotificationName: "AccountClosedPublisher", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR", + Expected: &NotificationNotificationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + NotificationName: "AccountClosedPublisher", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNotificationNotificationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.NotificationName != v.Expected.NotificationName { + t.Fatalf("Expected %q but got %q for NotificationName", v.Expected.NotificationName, actual.NotificationName) + } + + } +} + +func TestSegmentsForNotificationNotificationId(t *testing.T) { + segments := NotificationNotificationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NotificationNotificationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/notification/id_service.go b/resource-manager/apimanagement/2024-05-01/notification/id_service.go new file mode 100644 index 00000000000..a9b6b10ca5c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notification/id_service.go @@ -0,0 +1,130 @@ +package notification + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/notification/id_service_test.go b/resource-manager/apimanagement/2024-05-01/notification/id_service_test.go new file mode 100644 index 00000000000..bd37f2c75f2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notification/id_service_test.go @@ -0,0 +1,282 @@ +package notification + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/notification/id_workspace.go b/resource-manager/apimanagement/2024-05-01/notification/id_workspace.go new file mode 100644 index 00000000000..2a3893a9c73 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notification/id_workspace.go @@ -0,0 +1,139 @@ +package notification + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/notification/id_workspace_test.go b/resource-manager/apimanagement/2024-05-01/notification/id_workspace_test.go new file mode 100644 index 00000000000..c5d954ea853 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notification/id_workspace_test.go @@ -0,0 +1,327 @@ +package notification + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/notification/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/notification/method_createorupdate.go new file mode 100644 index 00000000000..f66ed7aa163 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notification/method_createorupdate.go @@ -0,0 +1,83 @@ +package notification + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *NotificationContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c NotificationClient) CreateOrUpdate(ctx context.Context, id NotificationId, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 NotificationContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/notification/method_get.go b/resource-manager/apimanagement/2024-05-01/notification/method_get.go new file mode 100644 index 00000000000..21cc5b2b6f4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notification/method_get.go @@ -0,0 +1,54 @@ +package notification + +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 *NotificationContract +} + +// Get ... +func (c NotificationClient) Get(ctx context.Context, id NotificationId) (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 NotificationContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/notification/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/notification/method_listbyservice.go new file mode 100644 index 00000000000..b8f071f58f8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notification/method_listbyservice.go @@ -0,0 +1,137 @@ +package notification + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]NotificationContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []NotificationContract +} + +type ListByServiceOperationOptions struct { + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c NotificationClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/notifications", 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 *[]NotificationContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c NotificationClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, NotificationContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c NotificationClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate NotificationContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]NotificationContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/notification/method_workspacenotificationcreateorupdate.go b/resource-manager/apimanagement/2024-05-01/notification/method_workspacenotificationcreateorupdate.go new file mode 100644 index 00000000000..f9129556c8d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notification/method_workspacenotificationcreateorupdate.go @@ -0,0 +1,83 @@ +package notification + +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 WorkspaceNotificationCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *NotificationContract +} + +type WorkspaceNotificationCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceNotificationCreateOrUpdateOperationOptions() WorkspaceNotificationCreateOrUpdateOperationOptions { + return WorkspaceNotificationCreateOrUpdateOperationOptions{} +} + +func (o WorkspaceNotificationCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceNotificationCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceNotificationCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceNotificationCreateOrUpdate ... +func (c NotificationClient) WorkspaceNotificationCreateOrUpdate(ctx context.Context, id NotificationNotificationId, options WorkspaceNotificationCreateOrUpdateOperationOptions) (result WorkspaceNotificationCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 NotificationContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/notification/method_workspacenotificationget.go b/resource-manager/apimanagement/2024-05-01/notification/method_workspacenotificationget.go new file mode 100644 index 00000000000..f9301d38cea --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notification/method_workspacenotificationget.go @@ -0,0 +1,54 @@ +package notification + +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 WorkspaceNotificationGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *NotificationContract +} + +// WorkspaceNotificationGet ... +func (c NotificationClient) WorkspaceNotificationGet(ctx context.Context, id NotificationNotificationId) (result WorkspaceNotificationGetOperationResponse, 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 NotificationContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/notification/method_workspacenotificationlistbyservice.go b/resource-manager/apimanagement/2024-05-01/notification/method_workspacenotificationlistbyservice.go new file mode 100644 index 00000000000..9c9bdd761b7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notification/method_workspacenotificationlistbyservice.go @@ -0,0 +1,137 @@ +package notification + +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 WorkspaceNotificationListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]NotificationContract +} + +type WorkspaceNotificationListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []NotificationContract +} + +type WorkspaceNotificationListByServiceOperationOptions struct { + Skip *int64 + Top *int64 +} + +func DefaultWorkspaceNotificationListByServiceOperationOptions() WorkspaceNotificationListByServiceOperationOptions { + return WorkspaceNotificationListByServiceOperationOptions{} +} + +func (o WorkspaceNotificationListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceNotificationListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceNotificationListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspaceNotificationListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceNotificationListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceNotificationListByService ... +func (c NotificationClient) WorkspaceNotificationListByService(ctx context.Context, id WorkspaceId, options WorkspaceNotificationListByServiceOperationOptions) (result WorkspaceNotificationListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspaceNotificationListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/notifications", 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 *[]NotificationContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceNotificationListByServiceComplete retrieves all the results into a single object +func (c NotificationClient) WorkspaceNotificationListByServiceComplete(ctx context.Context, id WorkspaceId, options WorkspaceNotificationListByServiceOperationOptions) (WorkspaceNotificationListByServiceCompleteResult, error) { + return c.WorkspaceNotificationListByServiceCompleteMatchingPredicate(ctx, id, options, NotificationContractOperationPredicate{}) +} + +// WorkspaceNotificationListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c NotificationClient) WorkspaceNotificationListByServiceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options WorkspaceNotificationListByServiceOperationOptions, predicate NotificationContractOperationPredicate) (result WorkspaceNotificationListByServiceCompleteResult, err error) { + items := make([]NotificationContract, 0) + + resp, err := c.WorkspaceNotificationListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceNotificationListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/notification/model_notificationcontract.go b/resource-manager/apimanagement/2024-05-01/notification/model_notificationcontract.go new file mode 100644 index 00000000000..c0b649e0bdb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notification/model_notificationcontract.go @@ -0,0 +1,11 @@ +package notification + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NotificationContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *NotificationContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/notification/model_notificationcontractproperties.go b/resource-manager/apimanagement/2024-05-01/notification/model_notificationcontractproperties.go new file mode 100644 index 00000000000..37b3fe7a679 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notification/model_notificationcontractproperties.go @@ -0,0 +1,10 @@ +package notification + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NotificationContractProperties struct { + Description *string `json:"description,omitempty"` + Recipients *RecipientsContractProperties `json:"recipients,omitempty"` + Title string `json:"title"` +} diff --git a/resource-manager/apimanagement/2024-05-01/notification/model_recipientscontractproperties.go b/resource-manager/apimanagement/2024-05-01/notification/model_recipientscontractproperties.go new file mode 100644 index 00000000000..8fa927f2dce --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notification/model_recipientscontractproperties.go @@ -0,0 +1,9 @@ +package notification + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecipientsContractProperties struct { + Emails *[]string `json:"emails,omitempty"` + Users *[]string `json:"users,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/notification/predicates.go b/resource-manager/apimanagement/2024-05-01/notification/predicates.go new file mode 100644 index 00000000000..7235194fc77 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notification/predicates.go @@ -0,0 +1,27 @@ +package notification + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NotificationContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p NotificationContractOperationPredicate) Matches(input NotificationContract) 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/apimanagement/2024-05-01/notification/version.go b/resource-manager/apimanagement/2024-05-01/notification/version.go new file mode 100644 index 00000000000..51ed0ce7ff2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notification/version.go @@ -0,0 +1,12 @@ +package notification + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/notification/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/README.md b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/README.md new file mode 100644 index 00000000000..d5ea9368891 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/README.md @@ -0,0 +1,150 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/notificationrecipientemail` Documentation + +The `notificationrecipientemail` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/notificationrecipientemail" +``` + + +### Client Initialization + +```go +client := notificationrecipientemail.NewNotificationRecipientEmailClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `NotificationRecipientEmailClient.CheckEntityExists` + +```go +ctx := context.TODO() +id := notificationrecipientemail.NewRecipientEmailID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "AccountClosedPublisher", "recipientEmailValue") + +read, err := client.CheckEntityExists(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NotificationRecipientEmailClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := notificationrecipientemail.NewRecipientEmailID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "AccountClosedPublisher", "recipientEmailValue") + +read, err := client.CreateOrUpdate(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NotificationRecipientEmailClient.Delete` + +```go +ctx := context.TODO() +id := notificationrecipientemail.NewRecipientEmailID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "AccountClosedPublisher", "recipientEmailValue") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NotificationRecipientEmailClient.ListByNotification` + +```go +ctx := context.TODO() +id := notificationrecipientemail.NewNotificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "AccountClosedPublisher") + +// alternatively `client.ListByNotification(ctx, id)` can be used to do batched pagination +items, err := client.ListByNotificationComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `NotificationRecipientEmailClient.WorkspaceNotificationRecipientEmailCheckEntityExists` + +```go +ctx := context.TODO() +id := notificationrecipientemail.NewNotificationRecipientEmailID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "AccountClosedPublisher", "recipientEmailValue") + +read, err := client.WorkspaceNotificationRecipientEmailCheckEntityExists(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NotificationRecipientEmailClient.WorkspaceNotificationRecipientEmailCreateOrUpdate` + +```go +ctx := context.TODO() +id := notificationrecipientemail.NewNotificationRecipientEmailID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "AccountClosedPublisher", "recipientEmailValue") + +read, err := client.WorkspaceNotificationRecipientEmailCreateOrUpdate(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NotificationRecipientEmailClient.WorkspaceNotificationRecipientEmailDelete` + +```go +ctx := context.TODO() +id := notificationrecipientemail.NewNotificationRecipientEmailID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "AccountClosedPublisher", "recipientEmailValue") + +read, err := client.WorkspaceNotificationRecipientEmailDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NotificationRecipientEmailClient.WorkspaceNotificationRecipientEmailListByNotification` + +```go +ctx := context.TODO() +id := notificationrecipientemail.NewNotificationNotificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "AccountClosedPublisher") + +// alternatively `client.WorkspaceNotificationRecipientEmailListByNotification(ctx, id)` can be used to do batched pagination +items, err := client.WorkspaceNotificationRecipientEmailListByNotificationComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/client.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/client.go new file mode 100644 index 00000000000..9975fccb850 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/client.go @@ -0,0 +1,26 @@ +package notificationrecipientemail + +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 NotificationRecipientEmailClient struct { + Client *resourcemanager.Client +} + +func NewNotificationRecipientEmailClientWithBaseURI(sdkApi sdkEnv.Api) (*NotificationRecipientEmailClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "notificationrecipientemail", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating NotificationRecipientEmailClient: %+v", err) + } + + return &NotificationRecipientEmailClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/constants.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/constants.go new file mode 100644 index 00000000000..85940aee54e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/constants.go @@ -0,0 +1,66 @@ +package notificationrecipientemail + +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 NotificationName string + +const ( + NotificationNameAccountClosedPublisher NotificationName = "AccountClosedPublisher" + NotificationNameBCC NotificationName = "BCC" + NotificationNameNewApplicationNotificationMessage NotificationName = "NewApplicationNotificationMessage" + NotificationNameNewIssuePublisherNotificationMessage NotificationName = "NewIssuePublisherNotificationMessage" + NotificationNamePurchasePublisherNotificationMessage NotificationName = "PurchasePublisherNotificationMessage" + NotificationNameQuotaLimitApproachingPublisherNotificationMessage NotificationName = "QuotaLimitApproachingPublisherNotificationMessage" + NotificationNameRequestPublisherNotificationMessage NotificationName = "RequestPublisherNotificationMessage" +) + +func PossibleValuesForNotificationName() []string { + return []string{ + string(NotificationNameAccountClosedPublisher), + string(NotificationNameBCC), + string(NotificationNameNewApplicationNotificationMessage), + string(NotificationNameNewIssuePublisherNotificationMessage), + string(NotificationNamePurchasePublisherNotificationMessage), + string(NotificationNameQuotaLimitApproachingPublisherNotificationMessage), + string(NotificationNameRequestPublisherNotificationMessage), + } +} + +func (s *NotificationName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseNotificationName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseNotificationName(input string) (*NotificationName, error) { + vals := map[string]NotificationName{ + "accountclosedpublisher": NotificationNameAccountClosedPublisher, + "bcc": NotificationNameBCC, + "newapplicationnotificationmessage": NotificationNameNewApplicationNotificationMessage, + "newissuepublishernotificationmessage": NotificationNameNewIssuePublisherNotificationMessage, + "purchasepublishernotificationmessage": NotificationNamePurchasePublisherNotificationMessage, + "quotalimitapproachingpublishernotificationmessage": NotificationNameQuotaLimitApproachingPublisherNotificationMessage, + "requestpublishernotificationmessage": NotificationNameRequestPublisherNotificationMessage, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NotificationName(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/id_notification.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/id_notification.go new file mode 100644 index 00000000000..85bab8ef752 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/id_notification.go @@ -0,0 +1,147 @@ +package notificationrecipientemail + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&NotificationId{}) +} + +var _ resourceids.ResourceId = &NotificationId{} + +// NotificationId is a struct representing the Resource ID for a Notification +type NotificationId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + NotificationName NotificationName +} + +// NewNotificationID returns a new NotificationId struct +func NewNotificationID(subscriptionId string, resourceGroupName string, serviceName string, notificationName NotificationName) NotificationId { + return NotificationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + NotificationName: notificationName, + } +} + +// ParseNotificationID parses 'input' into a NotificationId +func ParseNotificationID(input string) (*NotificationId, error) { + parser := resourceids.NewParserFromResourceIdType(&NotificationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NotificationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNotificationIDInsensitively parses 'input' case-insensitively into a NotificationId +// note: this method should only be used for API response data and not user input +func ParseNotificationIDInsensitively(input string) (*NotificationId, error) { + parser := resourceids.NewParserFromResourceIdType(&NotificationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NotificationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NotificationId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if v, ok := input.Parsed["notificationName"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "notificationName", input) + } + + notificationName, err := parseNotificationName(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.NotificationName = *notificationName + } + + return nil +} + +// ValidateNotificationID checks that 'input' can be parsed as a Notification ID +func ValidateNotificationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseNotificationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Notification ID +func (id NotificationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/notifications/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, string(id.NotificationName)) +} + +// Segments returns a slice of Resource ID Segments which comprise this Notification ID +func (id NotificationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticNotifications", "notifications", "notifications"), + resourceids.ConstantSegment("notificationName", PossibleValuesForNotificationName(), "AccountClosedPublisher"), + } +} + +// String returns a human-readable description of this Notification ID +func (id NotificationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Notification Name: %q", string(id.NotificationName)), + } + return fmt.Sprintf("Notification (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/id_notification_test.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/id_notification_test.go new file mode 100644 index 00000000000..76e69c64440 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/id_notification_test.go @@ -0,0 +1,327 @@ +package notificationrecipientemail + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &NotificationId{} + +func TestNewNotificationID(t *testing.T) { + id := NewNotificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "AccountClosedPublisher") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.NotificationName != "AccountClosedPublisher" { + t.Fatalf("Expected %q but got %q for Segment 'NotificationName'", id.NotificationName, "AccountClosedPublisher") + } +} + +func TestFormatNotificationID(t *testing.T) { + actual := NewNotificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "AccountClosedPublisher").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNotificationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NotificationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher", + Expected: &NotificationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + NotificationName: "AccountClosedPublisher", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNotificationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.NotificationName != v.Expected.NotificationName { + t.Fatalf("Expected %q but got %q for NotificationName", v.Expected.NotificationName, actual.NotificationName) + } + + } +} + +func TestParseNotificationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NotificationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/nOtIfIcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher", + Expected: &NotificationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + NotificationName: "AccountClosedPublisher", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR", + Expected: &NotificationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + NotificationName: "AccountClosedPublisher", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNotificationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.NotificationName != v.Expected.NotificationName { + t.Fatalf("Expected %q but got %q for NotificationName", v.Expected.NotificationName, actual.NotificationName) + } + + } +} + +func TestSegmentsForNotificationId(t *testing.T) { + segments := NotificationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NotificationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/id_notificationnotification.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/id_notificationnotification.go new file mode 100644 index 00000000000..b5257846bad --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/id_notificationnotification.go @@ -0,0 +1,156 @@ +package notificationrecipientemail + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&NotificationNotificationId{}) +} + +var _ resourceids.ResourceId = &NotificationNotificationId{} + +// NotificationNotificationId is a struct representing the Resource ID for a Notification Notification +type NotificationNotificationId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + NotificationName NotificationName +} + +// NewNotificationNotificationID returns a new NotificationNotificationId struct +func NewNotificationNotificationID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, notificationName NotificationName) NotificationNotificationId { + return NotificationNotificationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + NotificationName: notificationName, + } +} + +// ParseNotificationNotificationID parses 'input' into a NotificationNotificationId +func ParseNotificationNotificationID(input string) (*NotificationNotificationId, error) { + parser := resourceids.NewParserFromResourceIdType(&NotificationNotificationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NotificationNotificationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNotificationNotificationIDInsensitively parses 'input' case-insensitively into a NotificationNotificationId +// note: this method should only be used for API response data and not user input +func ParseNotificationNotificationIDInsensitively(input string) (*NotificationNotificationId, error) { + parser := resourceids.NewParserFromResourceIdType(&NotificationNotificationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NotificationNotificationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NotificationNotificationId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if v, ok := input.Parsed["notificationName"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "notificationName", input) + } + + notificationName, err := parseNotificationName(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.NotificationName = *notificationName + } + + return nil +} + +// ValidateNotificationNotificationID checks that 'input' can be parsed as a Notification Notification ID +func ValidateNotificationNotificationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseNotificationNotificationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Notification Notification ID +func (id NotificationNotificationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/notifications/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, string(id.NotificationName)) +} + +// Segments returns a slice of Resource ID Segments which comprise this Notification Notification ID +func (id NotificationNotificationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticNotifications", "notifications", "notifications"), + resourceids.ConstantSegment("notificationName", PossibleValuesForNotificationName(), "AccountClosedPublisher"), + } +} + +// String returns a human-readable description of this Notification Notification ID +func (id NotificationNotificationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Notification Name: %q", string(id.NotificationName)), + } + return fmt.Sprintf("Notification Notification (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/id_notificationnotification_test.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/id_notificationnotification_test.go new file mode 100644 index 00000000000..02b7aa584ad --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/id_notificationnotification_test.go @@ -0,0 +1,372 @@ +package notificationrecipientemail + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &NotificationNotificationId{} + +func TestNewNotificationNotificationID(t *testing.T) { + id := NewNotificationNotificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "AccountClosedPublisher") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.NotificationName != "AccountClosedPublisher" { + t.Fatalf("Expected %q but got %q for Segment 'NotificationName'", id.NotificationName, "AccountClosedPublisher") + } +} + +func TestFormatNotificationNotificationID(t *testing.T) { + actual := NewNotificationNotificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "AccountClosedPublisher").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNotificationNotificationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NotificationNotificationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher", + Expected: &NotificationNotificationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + NotificationName: "AccountClosedPublisher", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNotificationNotificationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.NotificationName != v.Expected.NotificationName { + t.Fatalf("Expected %q but got %q for NotificationName", v.Expected.NotificationName, actual.NotificationName) + } + + } +} + +func TestParseNotificationNotificationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NotificationNotificationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/nOtIfIcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher", + Expected: &NotificationNotificationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + NotificationName: "AccountClosedPublisher", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR", + Expected: &NotificationNotificationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + NotificationName: "AccountClosedPublisher", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNotificationNotificationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.NotificationName != v.Expected.NotificationName { + t.Fatalf("Expected %q but got %q for NotificationName", v.Expected.NotificationName, actual.NotificationName) + } + + } +} + +func TestSegmentsForNotificationNotificationId(t *testing.T) { + segments := NotificationNotificationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NotificationNotificationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/id_notificationrecipientemail.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/id_notificationrecipientemail.go new file mode 100644 index 00000000000..417bba3220c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/id_notificationrecipientemail.go @@ -0,0 +1,165 @@ +package notificationrecipientemail + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&NotificationRecipientEmailId{}) +} + +var _ resourceids.ResourceId = &NotificationRecipientEmailId{} + +// NotificationRecipientEmailId is a struct representing the Resource ID for a Notification Recipient Email +type NotificationRecipientEmailId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + NotificationName NotificationName + RecipientEmailName string +} + +// NewNotificationRecipientEmailID returns a new NotificationRecipientEmailId struct +func NewNotificationRecipientEmailID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, notificationName NotificationName, recipientEmailName string) NotificationRecipientEmailId { + return NotificationRecipientEmailId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + NotificationName: notificationName, + RecipientEmailName: recipientEmailName, + } +} + +// ParseNotificationRecipientEmailID parses 'input' into a NotificationRecipientEmailId +func ParseNotificationRecipientEmailID(input string) (*NotificationRecipientEmailId, error) { + parser := resourceids.NewParserFromResourceIdType(&NotificationRecipientEmailId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NotificationRecipientEmailId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNotificationRecipientEmailIDInsensitively parses 'input' case-insensitively into a NotificationRecipientEmailId +// note: this method should only be used for API response data and not user input +func ParseNotificationRecipientEmailIDInsensitively(input string) (*NotificationRecipientEmailId, error) { + parser := resourceids.NewParserFromResourceIdType(&NotificationRecipientEmailId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NotificationRecipientEmailId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NotificationRecipientEmailId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if v, ok := input.Parsed["notificationName"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "notificationName", input) + } + + notificationName, err := parseNotificationName(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.NotificationName = *notificationName + } + + if id.RecipientEmailName, ok = input.Parsed["recipientEmailName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "recipientEmailName", input) + } + + return nil +} + +// ValidateNotificationRecipientEmailID checks that 'input' can be parsed as a Notification Recipient Email ID +func ValidateNotificationRecipientEmailID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseNotificationRecipientEmailID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Notification Recipient Email ID +func (id NotificationRecipientEmailId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/notifications/%s/recipientEmails/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, string(id.NotificationName), id.RecipientEmailName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Notification Recipient Email ID +func (id NotificationRecipientEmailId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticNotifications", "notifications", "notifications"), + resourceids.ConstantSegment("notificationName", PossibleValuesForNotificationName(), "AccountClosedPublisher"), + resourceids.StaticSegment("staticRecipientEmails", "recipientEmails", "recipientEmails"), + resourceids.UserSpecifiedSegment("recipientEmailName", "recipientEmailValue"), + } +} + +// String returns a human-readable description of this Notification Recipient Email ID +func (id NotificationRecipientEmailId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Notification Name: %q", string(id.NotificationName)), + fmt.Sprintf("Recipient Email Name: %q", id.RecipientEmailName), + } + return fmt.Sprintf("Notification Recipient Email (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/id_notificationrecipientemail_test.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/id_notificationrecipientemail_test.go new file mode 100644 index 00000000000..af3ec1cb9a9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/id_notificationrecipientemail_test.go @@ -0,0 +1,417 @@ +package notificationrecipientemail + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &NotificationRecipientEmailId{} + +func TestNewNotificationRecipientEmailID(t *testing.T) { + id := NewNotificationRecipientEmailID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "AccountClosedPublisher", "recipientEmailValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.NotificationName != "AccountClosedPublisher" { + t.Fatalf("Expected %q but got %q for Segment 'NotificationName'", id.NotificationName, "AccountClosedPublisher") + } + + if id.RecipientEmailName != "recipientEmailValue" { + t.Fatalf("Expected %q but got %q for Segment 'RecipientEmailName'", id.RecipientEmailName, "recipientEmailValue") + } +} + +func TestFormatNotificationRecipientEmailID(t *testing.T) { + actual := NewNotificationRecipientEmailID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "AccountClosedPublisher", "recipientEmailValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher/recipientEmails/recipientEmailValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNotificationRecipientEmailID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NotificationRecipientEmailId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher/recipientEmails", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher/recipientEmails/recipientEmailValue", + Expected: &NotificationRecipientEmailId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + NotificationName: "AccountClosedPublisher", + RecipientEmailName: "recipientEmailValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher/recipientEmails/recipientEmailValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNotificationRecipientEmailID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.NotificationName != v.Expected.NotificationName { + t.Fatalf("Expected %q but got %q for NotificationName", v.Expected.NotificationName, actual.NotificationName) + } + + if actual.RecipientEmailName != v.Expected.RecipientEmailName { + t.Fatalf("Expected %q but got %q for RecipientEmailName", v.Expected.RecipientEmailName, actual.RecipientEmailName) + } + + } +} + +func TestParseNotificationRecipientEmailIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NotificationRecipientEmailId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/nOtIfIcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher/recipientEmails", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR/rEcIpIeNtEmAiLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher/recipientEmails/recipientEmailValue", + Expected: &NotificationRecipientEmailId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + NotificationName: "AccountClosedPublisher", + RecipientEmailName: "recipientEmailValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher/recipientEmails/recipientEmailValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR/rEcIpIeNtEmAiLs/rEcIpIeNtEmAiLvAlUe", + Expected: &NotificationRecipientEmailId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + NotificationName: "AccountClosedPublisher", + RecipientEmailName: "rEcIpIeNtEmAiLvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR/rEcIpIeNtEmAiLs/rEcIpIeNtEmAiLvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNotificationRecipientEmailIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.NotificationName != v.Expected.NotificationName { + t.Fatalf("Expected %q but got %q for NotificationName", v.Expected.NotificationName, actual.NotificationName) + } + + if actual.RecipientEmailName != v.Expected.RecipientEmailName { + t.Fatalf("Expected %q but got %q for RecipientEmailName", v.Expected.RecipientEmailName, actual.RecipientEmailName) + } + + } +} + +func TestSegmentsForNotificationRecipientEmailId(t *testing.T) { + segments := NotificationRecipientEmailId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NotificationRecipientEmailId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/id_recipientemail.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/id_recipientemail.go new file mode 100644 index 00000000000..ed228835ce6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/id_recipientemail.go @@ -0,0 +1,156 @@ +package notificationrecipientemail + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RecipientEmailId{}) +} + +var _ resourceids.ResourceId = &RecipientEmailId{} + +// RecipientEmailId is a struct representing the Resource ID for a Recipient Email +type RecipientEmailId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + NotificationName NotificationName + RecipientEmailName string +} + +// NewRecipientEmailID returns a new RecipientEmailId struct +func NewRecipientEmailID(subscriptionId string, resourceGroupName string, serviceName string, notificationName NotificationName, recipientEmailName string) RecipientEmailId { + return RecipientEmailId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + NotificationName: notificationName, + RecipientEmailName: recipientEmailName, + } +} + +// ParseRecipientEmailID parses 'input' into a RecipientEmailId +func ParseRecipientEmailID(input string) (*RecipientEmailId, error) { + parser := resourceids.NewParserFromResourceIdType(&RecipientEmailId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RecipientEmailId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRecipientEmailIDInsensitively parses 'input' case-insensitively into a RecipientEmailId +// note: this method should only be used for API response data and not user input +func ParseRecipientEmailIDInsensitively(input string) (*RecipientEmailId, error) { + parser := resourceids.NewParserFromResourceIdType(&RecipientEmailId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RecipientEmailId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RecipientEmailId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if v, ok := input.Parsed["notificationName"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "notificationName", input) + } + + notificationName, err := parseNotificationName(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.NotificationName = *notificationName + } + + if id.RecipientEmailName, ok = input.Parsed["recipientEmailName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "recipientEmailName", input) + } + + return nil +} + +// ValidateRecipientEmailID checks that 'input' can be parsed as a Recipient Email ID +func ValidateRecipientEmailID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRecipientEmailID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Recipient Email ID +func (id RecipientEmailId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/notifications/%s/recipientEmails/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, string(id.NotificationName), id.RecipientEmailName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Recipient Email ID +func (id RecipientEmailId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticNotifications", "notifications", "notifications"), + resourceids.ConstantSegment("notificationName", PossibleValuesForNotificationName(), "AccountClosedPublisher"), + resourceids.StaticSegment("staticRecipientEmails", "recipientEmails", "recipientEmails"), + resourceids.UserSpecifiedSegment("recipientEmailName", "recipientEmailValue"), + } +} + +// String returns a human-readable description of this Recipient Email ID +func (id RecipientEmailId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Notification Name: %q", string(id.NotificationName)), + fmt.Sprintf("Recipient Email Name: %q", id.RecipientEmailName), + } + return fmt.Sprintf("Recipient Email (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/id_recipientemail_test.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/id_recipientemail_test.go new file mode 100644 index 00000000000..88a07619e07 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/id_recipientemail_test.go @@ -0,0 +1,372 @@ +package notificationrecipientemail + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RecipientEmailId{} + +func TestNewRecipientEmailID(t *testing.T) { + id := NewRecipientEmailID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "AccountClosedPublisher", "recipientEmailValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.NotificationName != "AccountClosedPublisher" { + t.Fatalf("Expected %q but got %q for Segment 'NotificationName'", id.NotificationName, "AccountClosedPublisher") + } + + if id.RecipientEmailName != "recipientEmailValue" { + t.Fatalf("Expected %q but got %q for Segment 'RecipientEmailName'", id.RecipientEmailName, "recipientEmailValue") + } +} + +func TestFormatRecipientEmailID(t *testing.T) { + actual := NewRecipientEmailID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "AccountClosedPublisher", "recipientEmailValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher/recipientEmails/recipientEmailValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRecipientEmailID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RecipientEmailId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher/recipientEmails", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher/recipientEmails/recipientEmailValue", + Expected: &RecipientEmailId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + NotificationName: "AccountClosedPublisher", + RecipientEmailName: "recipientEmailValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher/recipientEmails/recipientEmailValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRecipientEmailID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.NotificationName != v.Expected.NotificationName { + t.Fatalf("Expected %q but got %q for NotificationName", v.Expected.NotificationName, actual.NotificationName) + } + + if actual.RecipientEmailName != v.Expected.RecipientEmailName { + t.Fatalf("Expected %q but got %q for RecipientEmailName", v.Expected.RecipientEmailName, actual.RecipientEmailName) + } + + } +} + +func TestParseRecipientEmailIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RecipientEmailId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/nOtIfIcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher/recipientEmails", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR/rEcIpIeNtEmAiLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher/recipientEmails/recipientEmailValue", + Expected: &RecipientEmailId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + NotificationName: "AccountClosedPublisher", + RecipientEmailName: "recipientEmailValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher/recipientEmails/recipientEmailValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR/rEcIpIeNtEmAiLs/rEcIpIeNtEmAiLvAlUe", + Expected: &RecipientEmailId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + NotificationName: "AccountClosedPublisher", + RecipientEmailName: "rEcIpIeNtEmAiLvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR/rEcIpIeNtEmAiLs/rEcIpIeNtEmAiLvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRecipientEmailIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.NotificationName != v.Expected.NotificationName { + t.Fatalf("Expected %q but got %q for NotificationName", v.Expected.NotificationName, actual.NotificationName) + } + + if actual.RecipientEmailName != v.Expected.RecipientEmailName { + t.Fatalf("Expected %q but got %q for RecipientEmailName", v.Expected.RecipientEmailName, actual.RecipientEmailName) + } + + } +} + +func TestSegmentsForRecipientEmailId(t *testing.T) { + segments := RecipientEmailId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RecipientEmailId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/method_checkentityexists.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/method_checkentityexists.go new file mode 100644 index 00000000000..acddee29b82 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/method_checkentityexists.go @@ -0,0 +1,46 @@ +package notificationrecipientemail + +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 CheckEntityExistsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CheckEntityExists ... +func (c NotificationRecipientEmailClient) CheckEntityExists(ctx context.Context, id RecipientEmailId) (result CheckEntityExistsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/method_createorupdate.go new file mode 100644 index 00000000000..c9ff8f4f049 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/method_createorupdate.go @@ -0,0 +1,55 @@ +package notificationrecipientemail + +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 *RecipientEmailContract +} + +// CreateOrUpdate ... +func (c NotificationRecipientEmailClient) CreateOrUpdate(ctx context.Context, id RecipientEmailId) (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 + } + + 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 RecipientEmailContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/method_delete.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/method_delete.go new file mode 100644 index 00000000000..083dbc0417f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/method_delete.go @@ -0,0 +1,47 @@ +package notificationrecipientemail + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c NotificationRecipientEmailClient) Delete(ctx context.Context, id RecipientEmailId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/method_listbynotification.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/method_listbynotification.go new file mode 100644 index 00000000000..8b4a8334e42 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/method_listbynotification.go @@ -0,0 +1,105 @@ +package notificationrecipientemail + +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 ListByNotificationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RecipientEmailContract +} + +type ListByNotificationCompleteResult struct { + LatestHttpResponse *http.Response + Items []RecipientEmailContract +} + +type ListByNotificationCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByNotificationCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByNotification ... +func (c NotificationRecipientEmailClient) ListByNotification(ctx context.Context, id NotificationId) (result ListByNotificationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByNotificationCustomPager{}, + Path: fmt.Sprintf("%s/recipientEmails", 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 *[]RecipientEmailContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByNotificationComplete retrieves all the results into a single object +func (c NotificationRecipientEmailClient) ListByNotificationComplete(ctx context.Context, id NotificationId) (ListByNotificationCompleteResult, error) { + return c.ListByNotificationCompleteMatchingPredicate(ctx, id, RecipientEmailContractOperationPredicate{}) +} + +// ListByNotificationCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c NotificationRecipientEmailClient) ListByNotificationCompleteMatchingPredicate(ctx context.Context, id NotificationId, predicate RecipientEmailContractOperationPredicate) (result ListByNotificationCompleteResult, err error) { + items := make([]RecipientEmailContract, 0) + + resp, err := c.ListByNotification(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByNotificationCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/method_workspacenotificationrecipientemailcheckentityexists.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/method_workspacenotificationrecipientemailcheckentityexists.go new file mode 100644 index 00000000000..7e6b7c04d1a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/method_workspacenotificationrecipientemailcheckentityexists.go @@ -0,0 +1,46 @@ +package notificationrecipientemail + +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 WorkspaceNotificationRecipientEmailCheckEntityExistsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceNotificationRecipientEmailCheckEntityExists ... +func (c NotificationRecipientEmailClient) WorkspaceNotificationRecipientEmailCheckEntityExists(ctx context.Context, id NotificationRecipientEmailId) (result WorkspaceNotificationRecipientEmailCheckEntityExistsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/method_workspacenotificationrecipientemailcreateorupdate.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/method_workspacenotificationrecipientemailcreateorupdate.go new file mode 100644 index 00000000000..a58726e1c6c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/method_workspacenotificationrecipientemailcreateorupdate.go @@ -0,0 +1,55 @@ +package notificationrecipientemail + +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 WorkspaceNotificationRecipientEmailCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RecipientEmailContract +} + +// WorkspaceNotificationRecipientEmailCreateOrUpdate ... +func (c NotificationRecipientEmailClient) WorkspaceNotificationRecipientEmailCreateOrUpdate(ctx context.Context, id NotificationRecipientEmailId) (result WorkspaceNotificationRecipientEmailCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RecipientEmailContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/method_workspacenotificationrecipientemaildelete.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/method_workspacenotificationrecipientemaildelete.go new file mode 100644 index 00000000000..08489b68901 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/method_workspacenotificationrecipientemaildelete.go @@ -0,0 +1,47 @@ +package notificationrecipientemail + +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 WorkspaceNotificationRecipientEmailDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceNotificationRecipientEmailDelete ... +func (c NotificationRecipientEmailClient) WorkspaceNotificationRecipientEmailDelete(ctx context.Context, id NotificationRecipientEmailId) (result WorkspaceNotificationRecipientEmailDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/method_workspacenotificationrecipientemaillistbynotification.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/method_workspacenotificationrecipientemaillistbynotification.go new file mode 100644 index 00000000000..42575e8657e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/method_workspacenotificationrecipientemaillistbynotification.go @@ -0,0 +1,105 @@ +package notificationrecipientemail + +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 WorkspaceNotificationRecipientEmailListByNotificationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RecipientEmailContract +} + +type WorkspaceNotificationRecipientEmailListByNotificationCompleteResult struct { + LatestHttpResponse *http.Response + Items []RecipientEmailContract +} + +type WorkspaceNotificationRecipientEmailListByNotificationCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceNotificationRecipientEmailListByNotificationCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceNotificationRecipientEmailListByNotification ... +func (c NotificationRecipientEmailClient) WorkspaceNotificationRecipientEmailListByNotification(ctx context.Context, id NotificationNotificationId) (result WorkspaceNotificationRecipientEmailListByNotificationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &WorkspaceNotificationRecipientEmailListByNotificationCustomPager{}, + Path: fmt.Sprintf("%s/recipientEmails", 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 *[]RecipientEmailContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceNotificationRecipientEmailListByNotificationComplete retrieves all the results into a single object +func (c NotificationRecipientEmailClient) WorkspaceNotificationRecipientEmailListByNotificationComplete(ctx context.Context, id NotificationNotificationId) (WorkspaceNotificationRecipientEmailListByNotificationCompleteResult, error) { + return c.WorkspaceNotificationRecipientEmailListByNotificationCompleteMatchingPredicate(ctx, id, RecipientEmailContractOperationPredicate{}) +} + +// WorkspaceNotificationRecipientEmailListByNotificationCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c NotificationRecipientEmailClient) WorkspaceNotificationRecipientEmailListByNotificationCompleteMatchingPredicate(ctx context.Context, id NotificationNotificationId, predicate RecipientEmailContractOperationPredicate) (result WorkspaceNotificationRecipientEmailListByNotificationCompleteResult, err error) { + items := make([]RecipientEmailContract, 0) + + resp, err := c.WorkspaceNotificationRecipientEmailListByNotification(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceNotificationRecipientEmailListByNotificationCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/model_recipientemailcontract.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/model_recipientemailcontract.go new file mode 100644 index 00000000000..08b49e04f7d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/model_recipientemailcontract.go @@ -0,0 +1,11 @@ +package notificationrecipientemail + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecipientEmailContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RecipientEmailContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/model_recipientemailcontractproperties.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/model_recipientemailcontractproperties.go new file mode 100644 index 00000000000..19b8d6b8787 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/model_recipientemailcontractproperties.go @@ -0,0 +1,8 @@ +package notificationrecipientemail + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecipientEmailContractProperties struct { + Email *string `json:"email,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/predicates.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/predicates.go new file mode 100644 index 00000000000..88f7177970c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/predicates.go @@ -0,0 +1,27 @@ +package notificationrecipientemail + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecipientEmailContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p RecipientEmailContractOperationPredicate) Matches(input RecipientEmailContract) 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/apimanagement/2024-05-01/notificationrecipientemail/version.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/version.go new file mode 100644 index 00000000000..5eab803396a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientemail/version.go @@ -0,0 +1,12 @@ +package notificationrecipientemail + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/notificationrecipientemail/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/README.md b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/README.md new file mode 100644 index 00000000000..fc68ca24166 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/README.md @@ -0,0 +1,150 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/notificationrecipientuser` Documentation + +The `notificationrecipientuser` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/notificationrecipientuser" +``` + + +### Client Initialization + +```go +client := notificationrecipientuser.NewNotificationRecipientUserClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `NotificationRecipientUserClient.CheckEntityExists` + +```go +ctx := context.TODO() +id := notificationrecipientuser.NewRecipientUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "AccountClosedPublisher", "userIdValue") + +read, err := client.CheckEntityExists(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NotificationRecipientUserClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := notificationrecipientuser.NewRecipientUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "AccountClosedPublisher", "userIdValue") + +read, err := client.CreateOrUpdate(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NotificationRecipientUserClient.Delete` + +```go +ctx := context.TODO() +id := notificationrecipientuser.NewRecipientUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "AccountClosedPublisher", "userIdValue") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NotificationRecipientUserClient.ListByNotification` + +```go +ctx := context.TODO() +id := notificationrecipientuser.NewNotificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "AccountClosedPublisher") + +// alternatively `client.ListByNotification(ctx, id)` can be used to do batched pagination +items, err := client.ListByNotificationComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `NotificationRecipientUserClient.WorkspaceNotificationRecipientUserCheckEntityExists` + +```go +ctx := context.TODO() +id := notificationrecipientuser.NewNotificationRecipientUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "AccountClosedPublisher", "userIdValue") + +read, err := client.WorkspaceNotificationRecipientUserCheckEntityExists(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NotificationRecipientUserClient.WorkspaceNotificationRecipientUserCreateOrUpdate` + +```go +ctx := context.TODO() +id := notificationrecipientuser.NewNotificationRecipientUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "AccountClosedPublisher", "userIdValue") + +read, err := client.WorkspaceNotificationRecipientUserCreateOrUpdate(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NotificationRecipientUserClient.WorkspaceNotificationRecipientUserDelete` + +```go +ctx := context.TODO() +id := notificationrecipientuser.NewNotificationRecipientUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "AccountClosedPublisher", "userIdValue") + +read, err := client.WorkspaceNotificationRecipientUserDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NotificationRecipientUserClient.WorkspaceNotificationRecipientUserListByNotification` + +```go +ctx := context.TODO() +id := notificationrecipientuser.NewNotificationNotificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "AccountClosedPublisher") + +// alternatively `client.WorkspaceNotificationRecipientUserListByNotification(ctx, id)` can be used to do batched pagination +items, err := client.WorkspaceNotificationRecipientUserListByNotificationComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/client.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/client.go new file mode 100644 index 00000000000..3049dccc74b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/client.go @@ -0,0 +1,26 @@ +package notificationrecipientuser + +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 NotificationRecipientUserClient struct { + Client *resourcemanager.Client +} + +func NewNotificationRecipientUserClientWithBaseURI(sdkApi sdkEnv.Api) (*NotificationRecipientUserClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "notificationrecipientuser", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating NotificationRecipientUserClient: %+v", err) + } + + return &NotificationRecipientUserClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/constants.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/constants.go new file mode 100644 index 00000000000..879dbf85c44 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/constants.go @@ -0,0 +1,66 @@ +package notificationrecipientuser + +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 NotificationName string + +const ( + NotificationNameAccountClosedPublisher NotificationName = "AccountClosedPublisher" + NotificationNameBCC NotificationName = "BCC" + NotificationNameNewApplicationNotificationMessage NotificationName = "NewApplicationNotificationMessage" + NotificationNameNewIssuePublisherNotificationMessage NotificationName = "NewIssuePublisherNotificationMessage" + NotificationNamePurchasePublisherNotificationMessage NotificationName = "PurchasePublisherNotificationMessage" + NotificationNameQuotaLimitApproachingPublisherNotificationMessage NotificationName = "QuotaLimitApproachingPublisherNotificationMessage" + NotificationNameRequestPublisherNotificationMessage NotificationName = "RequestPublisherNotificationMessage" +) + +func PossibleValuesForNotificationName() []string { + return []string{ + string(NotificationNameAccountClosedPublisher), + string(NotificationNameBCC), + string(NotificationNameNewApplicationNotificationMessage), + string(NotificationNameNewIssuePublisherNotificationMessage), + string(NotificationNamePurchasePublisherNotificationMessage), + string(NotificationNameQuotaLimitApproachingPublisherNotificationMessage), + string(NotificationNameRequestPublisherNotificationMessage), + } +} + +func (s *NotificationName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseNotificationName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseNotificationName(input string) (*NotificationName, error) { + vals := map[string]NotificationName{ + "accountclosedpublisher": NotificationNameAccountClosedPublisher, + "bcc": NotificationNameBCC, + "newapplicationnotificationmessage": NotificationNameNewApplicationNotificationMessage, + "newissuepublishernotificationmessage": NotificationNameNewIssuePublisherNotificationMessage, + "purchasepublishernotificationmessage": NotificationNamePurchasePublisherNotificationMessage, + "quotalimitapproachingpublishernotificationmessage": NotificationNameQuotaLimitApproachingPublisherNotificationMessage, + "requestpublishernotificationmessage": NotificationNameRequestPublisherNotificationMessage, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NotificationName(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/id_notification.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/id_notification.go new file mode 100644 index 00000000000..525816f0e3b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/id_notification.go @@ -0,0 +1,147 @@ +package notificationrecipientuser + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&NotificationId{}) +} + +var _ resourceids.ResourceId = &NotificationId{} + +// NotificationId is a struct representing the Resource ID for a Notification +type NotificationId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + NotificationName NotificationName +} + +// NewNotificationID returns a new NotificationId struct +func NewNotificationID(subscriptionId string, resourceGroupName string, serviceName string, notificationName NotificationName) NotificationId { + return NotificationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + NotificationName: notificationName, + } +} + +// ParseNotificationID parses 'input' into a NotificationId +func ParseNotificationID(input string) (*NotificationId, error) { + parser := resourceids.NewParserFromResourceIdType(&NotificationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NotificationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNotificationIDInsensitively parses 'input' case-insensitively into a NotificationId +// note: this method should only be used for API response data and not user input +func ParseNotificationIDInsensitively(input string) (*NotificationId, error) { + parser := resourceids.NewParserFromResourceIdType(&NotificationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NotificationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NotificationId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if v, ok := input.Parsed["notificationName"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "notificationName", input) + } + + notificationName, err := parseNotificationName(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.NotificationName = *notificationName + } + + return nil +} + +// ValidateNotificationID checks that 'input' can be parsed as a Notification ID +func ValidateNotificationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseNotificationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Notification ID +func (id NotificationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/notifications/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, string(id.NotificationName)) +} + +// Segments returns a slice of Resource ID Segments which comprise this Notification ID +func (id NotificationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticNotifications", "notifications", "notifications"), + resourceids.ConstantSegment("notificationName", PossibleValuesForNotificationName(), "AccountClosedPublisher"), + } +} + +// String returns a human-readable description of this Notification ID +func (id NotificationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Notification Name: %q", string(id.NotificationName)), + } + return fmt.Sprintf("Notification (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/id_notification_test.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/id_notification_test.go new file mode 100644 index 00000000000..ff1336f8f55 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/id_notification_test.go @@ -0,0 +1,327 @@ +package notificationrecipientuser + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &NotificationId{} + +func TestNewNotificationID(t *testing.T) { + id := NewNotificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "AccountClosedPublisher") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.NotificationName != "AccountClosedPublisher" { + t.Fatalf("Expected %q but got %q for Segment 'NotificationName'", id.NotificationName, "AccountClosedPublisher") + } +} + +func TestFormatNotificationID(t *testing.T) { + actual := NewNotificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "AccountClosedPublisher").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNotificationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NotificationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher", + Expected: &NotificationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + NotificationName: "AccountClosedPublisher", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNotificationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.NotificationName != v.Expected.NotificationName { + t.Fatalf("Expected %q but got %q for NotificationName", v.Expected.NotificationName, actual.NotificationName) + } + + } +} + +func TestParseNotificationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NotificationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/nOtIfIcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher", + Expected: &NotificationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + NotificationName: "AccountClosedPublisher", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR", + Expected: &NotificationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + NotificationName: "AccountClosedPublisher", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNotificationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.NotificationName != v.Expected.NotificationName { + t.Fatalf("Expected %q but got %q for NotificationName", v.Expected.NotificationName, actual.NotificationName) + } + + } +} + +func TestSegmentsForNotificationId(t *testing.T) { + segments := NotificationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NotificationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/id_notificationnotification.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/id_notificationnotification.go new file mode 100644 index 00000000000..86345fd0047 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/id_notificationnotification.go @@ -0,0 +1,156 @@ +package notificationrecipientuser + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&NotificationNotificationId{}) +} + +var _ resourceids.ResourceId = &NotificationNotificationId{} + +// NotificationNotificationId is a struct representing the Resource ID for a Notification Notification +type NotificationNotificationId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + NotificationName NotificationName +} + +// NewNotificationNotificationID returns a new NotificationNotificationId struct +func NewNotificationNotificationID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, notificationName NotificationName) NotificationNotificationId { + return NotificationNotificationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + NotificationName: notificationName, + } +} + +// ParseNotificationNotificationID parses 'input' into a NotificationNotificationId +func ParseNotificationNotificationID(input string) (*NotificationNotificationId, error) { + parser := resourceids.NewParserFromResourceIdType(&NotificationNotificationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NotificationNotificationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNotificationNotificationIDInsensitively parses 'input' case-insensitively into a NotificationNotificationId +// note: this method should only be used for API response data and not user input +func ParseNotificationNotificationIDInsensitively(input string) (*NotificationNotificationId, error) { + parser := resourceids.NewParserFromResourceIdType(&NotificationNotificationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NotificationNotificationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NotificationNotificationId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if v, ok := input.Parsed["notificationName"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "notificationName", input) + } + + notificationName, err := parseNotificationName(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.NotificationName = *notificationName + } + + return nil +} + +// ValidateNotificationNotificationID checks that 'input' can be parsed as a Notification Notification ID +func ValidateNotificationNotificationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseNotificationNotificationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Notification Notification ID +func (id NotificationNotificationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/notifications/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, string(id.NotificationName)) +} + +// Segments returns a slice of Resource ID Segments which comprise this Notification Notification ID +func (id NotificationNotificationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticNotifications", "notifications", "notifications"), + resourceids.ConstantSegment("notificationName", PossibleValuesForNotificationName(), "AccountClosedPublisher"), + } +} + +// String returns a human-readable description of this Notification Notification ID +func (id NotificationNotificationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Notification Name: %q", string(id.NotificationName)), + } + return fmt.Sprintf("Notification Notification (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/id_notificationnotification_test.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/id_notificationnotification_test.go new file mode 100644 index 00000000000..5dd606b306d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/id_notificationnotification_test.go @@ -0,0 +1,372 @@ +package notificationrecipientuser + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &NotificationNotificationId{} + +func TestNewNotificationNotificationID(t *testing.T) { + id := NewNotificationNotificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "AccountClosedPublisher") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.NotificationName != "AccountClosedPublisher" { + t.Fatalf("Expected %q but got %q for Segment 'NotificationName'", id.NotificationName, "AccountClosedPublisher") + } +} + +func TestFormatNotificationNotificationID(t *testing.T) { + actual := NewNotificationNotificationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "AccountClosedPublisher").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNotificationNotificationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NotificationNotificationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher", + Expected: &NotificationNotificationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + NotificationName: "AccountClosedPublisher", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNotificationNotificationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.NotificationName != v.Expected.NotificationName { + t.Fatalf("Expected %q but got %q for NotificationName", v.Expected.NotificationName, actual.NotificationName) + } + + } +} + +func TestParseNotificationNotificationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NotificationNotificationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/nOtIfIcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher", + Expected: &NotificationNotificationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + NotificationName: "AccountClosedPublisher", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR", + Expected: &NotificationNotificationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + NotificationName: "AccountClosedPublisher", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNotificationNotificationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.NotificationName != v.Expected.NotificationName { + t.Fatalf("Expected %q but got %q for NotificationName", v.Expected.NotificationName, actual.NotificationName) + } + + } +} + +func TestSegmentsForNotificationNotificationId(t *testing.T) { + segments := NotificationNotificationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NotificationNotificationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/id_notificationrecipientuser.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/id_notificationrecipientuser.go new file mode 100644 index 00000000000..abd829fc50b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/id_notificationrecipientuser.go @@ -0,0 +1,165 @@ +package notificationrecipientuser + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&NotificationRecipientUserId{}) +} + +var _ resourceids.ResourceId = &NotificationRecipientUserId{} + +// NotificationRecipientUserId is a struct representing the Resource ID for a Notification Recipient User +type NotificationRecipientUserId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + NotificationName NotificationName + UserId string +} + +// NewNotificationRecipientUserID returns a new NotificationRecipientUserId struct +func NewNotificationRecipientUserID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, notificationName NotificationName, userId string) NotificationRecipientUserId { + return NotificationRecipientUserId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + NotificationName: notificationName, + UserId: userId, + } +} + +// ParseNotificationRecipientUserID parses 'input' into a NotificationRecipientUserId +func ParseNotificationRecipientUserID(input string) (*NotificationRecipientUserId, error) { + parser := resourceids.NewParserFromResourceIdType(&NotificationRecipientUserId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NotificationRecipientUserId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNotificationRecipientUserIDInsensitively parses 'input' case-insensitively into a NotificationRecipientUserId +// note: this method should only be used for API response data and not user input +func ParseNotificationRecipientUserIDInsensitively(input string) (*NotificationRecipientUserId, error) { + parser := resourceids.NewParserFromResourceIdType(&NotificationRecipientUserId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NotificationRecipientUserId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NotificationRecipientUserId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if v, ok := input.Parsed["notificationName"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "notificationName", input) + } + + notificationName, err := parseNotificationName(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.NotificationName = *notificationName + } + + if id.UserId, ok = input.Parsed["userId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "userId", input) + } + + return nil +} + +// ValidateNotificationRecipientUserID checks that 'input' can be parsed as a Notification Recipient User ID +func ValidateNotificationRecipientUserID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseNotificationRecipientUserID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Notification Recipient User ID +func (id NotificationRecipientUserId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/notifications/%s/recipientUsers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, string(id.NotificationName), id.UserId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Notification Recipient User ID +func (id NotificationRecipientUserId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticNotifications", "notifications", "notifications"), + resourceids.ConstantSegment("notificationName", PossibleValuesForNotificationName(), "AccountClosedPublisher"), + resourceids.StaticSegment("staticRecipientUsers", "recipientUsers", "recipientUsers"), + resourceids.UserSpecifiedSegment("userId", "userIdValue"), + } +} + +// String returns a human-readable description of this Notification Recipient User ID +func (id NotificationRecipientUserId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Notification Name: %q", string(id.NotificationName)), + fmt.Sprintf("User: %q", id.UserId), + } + return fmt.Sprintf("Notification Recipient User (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/id_notificationrecipientuser_test.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/id_notificationrecipientuser_test.go new file mode 100644 index 00000000000..434e0e15ae9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/id_notificationrecipientuser_test.go @@ -0,0 +1,417 @@ +package notificationrecipientuser + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &NotificationRecipientUserId{} + +func TestNewNotificationRecipientUserID(t *testing.T) { + id := NewNotificationRecipientUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "AccountClosedPublisher", "userIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.NotificationName != "AccountClosedPublisher" { + t.Fatalf("Expected %q but got %q for Segment 'NotificationName'", id.NotificationName, "AccountClosedPublisher") + } + + if id.UserId != "userIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'UserId'", id.UserId, "userIdValue") + } +} + +func TestFormatNotificationRecipientUserID(t *testing.T) { + actual := NewNotificationRecipientUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "AccountClosedPublisher", "userIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher/recipientUsers/userIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNotificationRecipientUserID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NotificationRecipientUserId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher/recipientUsers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher/recipientUsers/userIdValue", + Expected: &NotificationRecipientUserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + NotificationName: "AccountClosedPublisher", + UserId: "userIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher/recipientUsers/userIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNotificationRecipientUserID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.NotificationName != v.Expected.NotificationName { + t.Fatalf("Expected %q but got %q for NotificationName", v.Expected.NotificationName, actual.NotificationName) + } + + if actual.UserId != v.Expected.UserId { + t.Fatalf("Expected %q but got %q for UserId", v.Expected.UserId, actual.UserId) + } + + } +} + +func TestParseNotificationRecipientUserIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NotificationRecipientUserId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/nOtIfIcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher/recipientUsers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR/rEcIpIeNtUsErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher/recipientUsers/userIdValue", + Expected: &NotificationRecipientUserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + NotificationName: "AccountClosedPublisher", + UserId: "userIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/notifications/AccountClosedPublisher/recipientUsers/userIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR/rEcIpIeNtUsErS/uSeRiDvAlUe", + Expected: &NotificationRecipientUserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + NotificationName: "AccountClosedPublisher", + UserId: "uSeRiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR/rEcIpIeNtUsErS/uSeRiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNotificationRecipientUserIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.NotificationName != v.Expected.NotificationName { + t.Fatalf("Expected %q but got %q for NotificationName", v.Expected.NotificationName, actual.NotificationName) + } + + if actual.UserId != v.Expected.UserId { + t.Fatalf("Expected %q but got %q for UserId", v.Expected.UserId, actual.UserId) + } + + } +} + +func TestSegmentsForNotificationRecipientUserId(t *testing.T) { + segments := NotificationRecipientUserId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NotificationRecipientUserId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/id_recipientuser.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/id_recipientuser.go new file mode 100644 index 00000000000..1c6e88f7af0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/id_recipientuser.go @@ -0,0 +1,156 @@ +package notificationrecipientuser + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RecipientUserId{}) +} + +var _ resourceids.ResourceId = &RecipientUserId{} + +// RecipientUserId is a struct representing the Resource ID for a Recipient User +type RecipientUserId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + NotificationName NotificationName + UserId string +} + +// NewRecipientUserID returns a new RecipientUserId struct +func NewRecipientUserID(subscriptionId string, resourceGroupName string, serviceName string, notificationName NotificationName, userId string) RecipientUserId { + return RecipientUserId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + NotificationName: notificationName, + UserId: userId, + } +} + +// ParseRecipientUserID parses 'input' into a RecipientUserId +func ParseRecipientUserID(input string) (*RecipientUserId, error) { + parser := resourceids.NewParserFromResourceIdType(&RecipientUserId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RecipientUserId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRecipientUserIDInsensitively parses 'input' case-insensitively into a RecipientUserId +// note: this method should only be used for API response data and not user input +func ParseRecipientUserIDInsensitively(input string) (*RecipientUserId, error) { + parser := resourceids.NewParserFromResourceIdType(&RecipientUserId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RecipientUserId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RecipientUserId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if v, ok := input.Parsed["notificationName"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "notificationName", input) + } + + notificationName, err := parseNotificationName(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.NotificationName = *notificationName + } + + if id.UserId, ok = input.Parsed["userId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "userId", input) + } + + return nil +} + +// ValidateRecipientUserID checks that 'input' can be parsed as a Recipient User ID +func ValidateRecipientUserID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRecipientUserID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Recipient User ID +func (id RecipientUserId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/notifications/%s/recipientUsers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, string(id.NotificationName), id.UserId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Recipient User ID +func (id RecipientUserId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticNotifications", "notifications", "notifications"), + resourceids.ConstantSegment("notificationName", PossibleValuesForNotificationName(), "AccountClosedPublisher"), + resourceids.StaticSegment("staticRecipientUsers", "recipientUsers", "recipientUsers"), + resourceids.UserSpecifiedSegment("userId", "userIdValue"), + } +} + +// String returns a human-readable description of this Recipient User ID +func (id RecipientUserId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Notification Name: %q", string(id.NotificationName)), + fmt.Sprintf("User: %q", id.UserId), + } + return fmt.Sprintf("Recipient User (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/id_recipientuser_test.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/id_recipientuser_test.go new file mode 100644 index 00000000000..aaa72944b51 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/id_recipientuser_test.go @@ -0,0 +1,372 @@ +package notificationrecipientuser + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RecipientUserId{} + +func TestNewRecipientUserID(t *testing.T) { + id := NewRecipientUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "AccountClosedPublisher", "userIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.NotificationName != "AccountClosedPublisher" { + t.Fatalf("Expected %q but got %q for Segment 'NotificationName'", id.NotificationName, "AccountClosedPublisher") + } + + if id.UserId != "userIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'UserId'", id.UserId, "userIdValue") + } +} + +func TestFormatRecipientUserID(t *testing.T) { + actual := NewRecipientUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "AccountClosedPublisher", "userIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher/recipientUsers/userIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRecipientUserID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RecipientUserId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher/recipientUsers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher/recipientUsers/userIdValue", + Expected: &RecipientUserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + NotificationName: "AccountClosedPublisher", + UserId: "userIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher/recipientUsers/userIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRecipientUserID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.NotificationName != v.Expected.NotificationName { + t.Fatalf("Expected %q but got %q for NotificationName", v.Expected.NotificationName, actual.NotificationName) + } + + if actual.UserId != v.Expected.UserId { + t.Fatalf("Expected %q but got %q for UserId", v.Expected.UserId, actual.UserId) + } + + } +} + +func TestParseRecipientUserIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RecipientUserId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/nOtIfIcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher/recipientUsers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR/rEcIpIeNtUsErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher/recipientUsers/userIdValue", + Expected: &RecipientUserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + NotificationName: "AccountClosedPublisher", + UserId: "userIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/notifications/AccountClosedPublisher/recipientUsers/userIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR/rEcIpIeNtUsErS/uSeRiDvAlUe", + Expected: &RecipientUserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + NotificationName: "AccountClosedPublisher", + UserId: "uSeRiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/nOtIfIcAtIoNs/aCcOuNtClOsEdPuBlIsHeR/rEcIpIeNtUsErS/uSeRiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRecipientUserIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.NotificationName != v.Expected.NotificationName { + t.Fatalf("Expected %q but got %q for NotificationName", v.Expected.NotificationName, actual.NotificationName) + } + + if actual.UserId != v.Expected.UserId { + t.Fatalf("Expected %q but got %q for UserId", v.Expected.UserId, actual.UserId) + } + + } +} + +func TestSegmentsForRecipientUserId(t *testing.T) { + segments := RecipientUserId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RecipientUserId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/method_checkentityexists.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/method_checkentityexists.go new file mode 100644 index 00000000000..baae87b86d1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/method_checkentityexists.go @@ -0,0 +1,46 @@ +package notificationrecipientuser + +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 CheckEntityExistsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CheckEntityExists ... +func (c NotificationRecipientUserClient) CheckEntityExists(ctx context.Context, id RecipientUserId) (result CheckEntityExistsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/method_createorupdate.go new file mode 100644 index 00000000000..0736b330824 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/method_createorupdate.go @@ -0,0 +1,55 @@ +package notificationrecipientuser + +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 *RecipientUserContract +} + +// CreateOrUpdate ... +func (c NotificationRecipientUserClient) CreateOrUpdate(ctx context.Context, id RecipientUserId) (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 + } + + 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 RecipientUserContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/method_delete.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/method_delete.go new file mode 100644 index 00000000000..d0bf672da2e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/method_delete.go @@ -0,0 +1,47 @@ +package notificationrecipientuser + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c NotificationRecipientUserClient) Delete(ctx context.Context, id RecipientUserId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/method_listbynotification.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/method_listbynotification.go new file mode 100644 index 00000000000..c5c24a45310 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/method_listbynotification.go @@ -0,0 +1,105 @@ +package notificationrecipientuser + +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 ListByNotificationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RecipientUserContract +} + +type ListByNotificationCompleteResult struct { + LatestHttpResponse *http.Response + Items []RecipientUserContract +} + +type ListByNotificationCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByNotificationCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByNotification ... +func (c NotificationRecipientUserClient) ListByNotification(ctx context.Context, id NotificationId) (result ListByNotificationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByNotificationCustomPager{}, + Path: fmt.Sprintf("%s/recipientUsers", 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 *[]RecipientUserContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByNotificationComplete retrieves all the results into a single object +func (c NotificationRecipientUserClient) ListByNotificationComplete(ctx context.Context, id NotificationId) (ListByNotificationCompleteResult, error) { + return c.ListByNotificationCompleteMatchingPredicate(ctx, id, RecipientUserContractOperationPredicate{}) +} + +// ListByNotificationCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c NotificationRecipientUserClient) ListByNotificationCompleteMatchingPredicate(ctx context.Context, id NotificationId, predicate RecipientUserContractOperationPredicate) (result ListByNotificationCompleteResult, err error) { + items := make([]RecipientUserContract, 0) + + resp, err := c.ListByNotification(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByNotificationCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/method_workspacenotificationrecipientusercheckentityexists.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/method_workspacenotificationrecipientusercheckentityexists.go new file mode 100644 index 00000000000..c97509fc283 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/method_workspacenotificationrecipientusercheckentityexists.go @@ -0,0 +1,46 @@ +package notificationrecipientuser + +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 WorkspaceNotificationRecipientUserCheckEntityExistsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceNotificationRecipientUserCheckEntityExists ... +func (c NotificationRecipientUserClient) WorkspaceNotificationRecipientUserCheckEntityExists(ctx context.Context, id NotificationRecipientUserId) (result WorkspaceNotificationRecipientUserCheckEntityExistsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/method_workspacenotificationrecipientusercreateorupdate.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/method_workspacenotificationrecipientusercreateorupdate.go new file mode 100644 index 00000000000..ee963934976 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/method_workspacenotificationrecipientusercreateorupdate.go @@ -0,0 +1,55 @@ +package notificationrecipientuser + +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 WorkspaceNotificationRecipientUserCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RecipientUserContract +} + +// WorkspaceNotificationRecipientUserCreateOrUpdate ... +func (c NotificationRecipientUserClient) WorkspaceNotificationRecipientUserCreateOrUpdate(ctx context.Context, id NotificationRecipientUserId) (result WorkspaceNotificationRecipientUserCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RecipientUserContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/method_workspacenotificationrecipientuserdelete.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/method_workspacenotificationrecipientuserdelete.go new file mode 100644 index 00000000000..9faf1e4e761 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/method_workspacenotificationrecipientuserdelete.go @@ -0,0 +1,47 @@ +package notificationrecipientuser + +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 WorkspaceNotificationRecipientUserDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceNotificationRecipientUserDelete ... +func (c NotificationRecipientUserClient) WorkspaceNotificationRecipientUserDelete(ctx context.Context, id NotificationRecipientUserId) (result WorkspaceNotificationRecipientUserDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/method_workspacenotificationrecipientuserlistbynotification.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/method_workspacenotificationrecipientuserlistbynotification.go new file mode 100644 index 00000000000..0665d50ca9c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/method_workspacenotificationrecipientuserlistbynotification.go @@ -0,0 +1,105 @@ +package notificationrecipientuser + +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 WorkspaceNotificationRecipientUserListByNotificationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RecipientUserContract +} + +type WorkspaceNotificationRecipientUserListByNotificationCompleteResult struct { + LatestHttpResponse *http.Response + Items []RecipientUserContract +} + +type WorkspaceNotificationRecipientUserListByNotificationCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceNotificationRecipientUserListByNotificationCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceNotificationRecipientUserListByNotification ... +func (c NotificationRecipientUserClient) WorkspaceNotificationRecipientUserListByNotification(ctx context.Context, id NotificationNotificationId) (result WorkspaceNotificationRecipientUserListByNotificationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &WorkspaceNotificationRecipientUserListByNotificationCustomPager{}, + Path: fmt.Sprintf("%s/recipientUsers", 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 *[]RecipientUserContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceNotificationRecipientUserListByNotificationComplete retrieves all the results into a single object +func (c NotificationRecipientUserClient) WorkspaceNotificationRecipientUserListByNotificationComplete(ctx context.Context, id NotificationNotificationId) (WorkspaceNotificationRecipientUserListByNotificationCompleteResult, error) { + return c.WorkspaceNotificationRecipientUserListByNotificationCompleteMatchingPredicate(ctx, id, RecipientUserContractOperationPredicate{}) +} + +// WorkspaceNotificationRecipientUserListByNotificationCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c NotificationRecipientUserClient) WorkspaceNotificationRecipientUserListByNotificationCompleteMatchingPredicate(ctx context.Context, id NotificationNotificationId, predicate RecipientUserContractOperationPredicate) (result WorkspaceNotificationRecipientUserListByNotificationCompleteResult, err error) { + items := make([]RecipientUserContract, 0) + + resp, err := c.WorkspaceNotificationRecipientUserListByNotification(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceNotificationRecipientUserListByNotificationCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/model_recipientusercontract.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/model_recipientusercontract.go new file mode 100644 index 00000000000..9efe2cc9097 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/model_recipientusercontract.go @@ -0,0 +1,11 @@ +package notificationrecipientuser + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecipientUserContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RecipientUsersContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/model_recipientuserscontractproperties.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/model_recipientuserscontractproperties.go new file mode 100644 index 00000000000..2c8303f3740 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/model_recipientuserscontractproperties.go @@ -0,0 +1,8 @@ +package notificationrecipientuser + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecipientUsersContractProperties struct { + UserId *string `json:"userId,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/predicates.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/predicates.go new file mode 100644 index 00000000000..83ae9b3f94b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/predicates.go @@ -0,0 +1,27 @@ +package notificationrecipientuser + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecipientUserContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p RecipientUserContractOperationPredicate) Matches(input RecipientUserContract) 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/apimanagement/2024-05-01/notificationrecipientuser/version.go b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/version.go new file mode 100644 index 00000000000..015893083fc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/notificationrecipientuser/version.go @@ -0,0 +1,12 @@ +package notificationrecipientuser + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/notificationrecipientuser/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/openidconnectprovider/README.md b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/README.md new file mode 100644 index 00000000000..0b69fbd4670 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/README.md @@ -0,0 +1,143 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/openidconnectprovider` Documentation + +The `openidconnectprovider` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/openidconnectprovider" +``` + + +### Client Initialization + +```go +client := openidconnectprovider.NewOpenidConnectProviderClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `OpenidConnectProviderClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := openidconnectprovider.NewOpenidConnectProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "openidConnectProviderValue") + +payload := openidconnectprovider.OpenidConnectProviderContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, openidconnectprovider.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `OpenidConnectProviderClient.Delete` + +```go +ctx := context.TODO() +id := openidconnectprovider.NewOpenidConnectProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "openidConnectProviderValue") + +read, err := client.Delete(ctx, id, openidconnectprovider.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `OpenidConnectProviderClient.Get` + +```go +ctx := context.TODO() +id := openidconnectprovider.NewOpenidConnectProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "openidConnectProviderValue") + +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: `OpenidConnectProviderClient.GetEntityTag` + +```go +ctx := context.TODO() +id := openidconnectprovider.NewOpenidConnectProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "openidConnectProviderValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `OpenidConnectProviderClient.ListByService` + +```go +ctx := context.TODO() +id := openidconnectprovider.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, openidconnectprovider.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, openidconnectprovider.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `OpenidConnectProviderClient.ListSecrets` + +```go +ctx := context.TODO() +id := openidconnectprovider.NewOpenidConnectProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "openidConnectProviderValue") + +read, err := client.ListSecrets(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `OpenidConnectProviderClient.Update` + +```go +ctx := context.TODO() +id := openidconnectprovider.NewOpenidConnectProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "openidConnectProviderValue") + +payload := openidconnectprovider.OpenidConnectProviderUpdateContract{ + // ... +} + + +read, err := client.Update(ctx, id, payload, openidconnectprovider.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/openidconnectprovider/client.go b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/client.go new file mode 100644 index 00000000000..6b2113dfc3d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/client.go @@ -0,0 +1,26 @@ +package openidconnectprovider + +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 OpenidConnectProviderClient struct { + Client *resourcemanager.Client +} + +func NewOpenidConnectProviderClientWithBaseURI(sdkApi sdkEnv.Api) (*OpenidConnectProviderClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "openidconnectprovider", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating OpenidConnectProviderClient: %+v", err) + } + + return &OpenidConnectProviderClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/openidconnectprovider/id_openidconnectprovider.go b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/id_openidconnectprovider.go new file mode 100644 index 00000000000..b1e20b39388 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/id_openidconnectprovider.go @@ -0,0 +1,139 @@ +package openidconnectprovider + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&OpenidConnectProviderId{}) +} + +var _ resourceids.ResourceId = &OpenidConnectProviderId{} + +// OpenidConnectProviderId is a struct representing the Resource ID for a Openid Connect Provider +type OpenidConnectProviderId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + OpenidConnectProviderName string +} + +// NewOpenidConnectProviderID returns a new OpenidConnectProviderId struct +func NewOpenidConnectProviderID(subscriptionId string, resourceGroupName string, serviceName string, openidConnectProviderName string) OpenidConnectProviderId { + return OpenidConnectProviderId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + OpenidConnectProviderName: openidConnectProviderName, + } +} + +// ParseOpenidConnectProviderID parses 'input' into a OpenidConnectProviderId +func ParseOpenidConnectProviderID(input string) (*OpenidConnectProviderId, error) { + parser := resourceids.NewParserFromResourceIdType(&OpenidConnectProviderId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OpenidConnectProviderId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseOpenidConnectProviderIDInsensitively parses 'input' case-insensitively into a OpenidConnectProviderId +// note: this method should only be used for API response data and not user input +func ParseOpenidConnectProviderIDInsensitively(input string) (*OpenidConnectProviderId, error) { + parser := resourceids.NewParserFromResourceIdType(&OpenidConnectProviderId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OpenidConnectProviderId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *OpenidConnectProviderId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.OpenidConnectProviderName, ok = input.Parsed["openidConnectProviderName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "openidConnectProviderName", input) + } + + return nil +} + +// ValidateOpenidConnectProviderID checks that 'input' can be parsed as a Openid Connect Provider ID +func ValidateOpenidConnectProviderID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseOpenidConnectProviderID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Openid Connect Provider ID +func (id OpenidConnectProviderId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/openidConnectProviders/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.OpenidConnectProviderName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Openid Connect Provider ID +func (id OpenidConnectProviderId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticOpenidConnectProviders", "openidConnectProviders", "openidConnectProviders"), + resourceids.UserSpecifiedSegment("openidConnectProviderName", "openidConnectProviderValue"), + } +} + +// String returns a human-readable description of this Openid Connect Provider ID +func (id OpenidConnectProviderId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Openid Connect Provider Name: %q", id.OpenidConnectProviderName), + } + return fmt.Sprintf("Openid Connect Provider (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/openidconnectprovider/id_openidconnectprovider_test.go b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/id_openidconnectprovider_test.go new file mode 100644 index 00000000000..4186af8a0a1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/id_openidconnectprovider_test.go @@ -0,0 +1,327 @@ +package openidconnectprovider + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &OpenidConnectProviderId{} + +func TestNewOpenidConnectProviderID(t *testing.T) { + id := NewOpenidConnectProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "openidConnectProviderValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.OpenidConnectProviderName != "openidConnectProviderValue" { + t.Fatalf("Expected %q but got %q for Segment 'OpenidConnectProviderName'", id.OpenidConnectProviderName, "openidConnectProviderValue") + } +} + +func TestFormatOpenidConnectProviderID(t *testing.T) { + actual := NewOpenidConnectProviderID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "openidConnectProviderValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/openidConnectProviders/openidConnectProviderValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseOpenidConnectProviderID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OpenidConnectProviderId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/openidConnectProviders", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/openidConnectProviders/openidConnectProviderValue", + Expected: &OpenidConnectProviderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + OpenidConnectProviderName: "openidConnectProviderValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/openidConnectProviders/openidConnectProviderValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOpenidConnectProviderID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.OpenidConnectProviderName != v.Expected.OpenidConnectProviderName { + t.Fatalf("Expected %q but got %q for OpenidConnectProviderName", v.Expected.OpenidConnectProviderName, actual.OpenidConnectProviderName) + } + + } +} + +func TestParseOpenidConnectProviderIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OpenidConnectProviderId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/openidConnectProviders", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/oPeNiDcOnNeCtPrOvIdErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/openidConnectProviders/openidConnectProviderValue", + Expected: &OpenidConnectProviderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + OpenidConnectProviderName: "openidConnectProviderValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/openidConnectProviders/openidConnectProviderValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/oPeNiDcOnNeCtPrOvIdErS/oPeNiDcOnNeCtPrOvIdErVaLuE", + Expected: &OpenidConnectProviderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + OpenidConnectProviderName: "oPeNiDcOnNeCtPrOvIdErVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/oPeNiDcOnNeCtPrOvIdErS/oPeNiDcOnNeCtPrOvIdErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOpenidConnectProviderIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.OpenidConnectProviderName != v.Expected.OpenidConnectProviderName { + t.Fatalf("Expected %q but got %q for OpenidConnectProviderName", v.Expected.OpenidConnectProviderName, actual.OpenidConnectProviderName) + } + + } +} + +func TestSegmentsForOpenidConnectProviderId(t *testing.T) { + segments := OpenidConnectProviderId{}.Segments() + if len(segments) == 0 { + t.Fatalf("OpenidConnectProviderId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/openidconnectprovider/id_service.go b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/id_service.go new file mode 100644 index 00000000000..992d2595802 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/id_service.go @@ -0,0 +1,130 @@ +package openidconnectprovider + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/openidconnectprovider/id_service_test.go b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/id_service_test.go new file mode 100644 index 00000000000..6c109ad2ea8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/id_service_test.go @@ -0,0 +1,282 @@ +package openidconnectprovider + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/openidconnectprovider/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/method_createorupdate.go new file mode 100644 index 00000000000..ab5c53bdaa6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/method_createorupdate.go @@ -0,0 +1,88 @@ +package openidconnectprovider + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *OpenidConnectProviderContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c OpenidConnectProviderClient) CreateOrUpdate(ctx context.Context, id OpenidConnectProviderId, input OpenidConnectProviderContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 OpenidConnectProviderContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/openidconnectprovider/method_delete.go b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/method_delete.go new file mode 100644 index 00000000000..d434f5eff61 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/method_delete.go @@ -0,0 +1,76 @@ +package openidconnectprovider + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c OpenidConnectProviderClient) Delete(ctx context.Context, id OpenidConnectProviderId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/openidconnectprovider/method_get.go b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/method_get.go new file mode 100644 index 00000000000..642a146fa5f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/method_get.go @@ -0,0 +1,54 @@ +package openidconnectprovider + +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 *OpenidConnectProviderContract +} + +// Get ... +func (c OpenidConnectProviderClient) Get(ctx context.Context, id OpenidConnectProviderId) (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 OpenidConnectProviderContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/openidconnectprovider/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/method_getentitytag.go new file mode 100644 index 00000000000..3f411d67cae --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/method_getentitytag.go @@ -0,0 +1,46 @@ +package openidconnectprovider + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c OpenidConnectProviderClient) GetEntityTag(ctx context.Context, id OpenidConnectProviderId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/openidconnectprovider/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/method_listbyservice.go new file mode 100644 index 00000000000..a4b2de8c3dc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/method_listbyservice.go @@ -0,0 +1,141 @@ +package openidconnectprovider + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]OpenidConnectProviderContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []OpenidConnectProviderContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c OpenidConnectProviderClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/openidConnectProviders", 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 *[]OpenidConnectProviderContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c OpenidConnectProviderClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, OpenidConnectProviderContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c OpenidConnectProviderClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate OpenidConnectProviderContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]OpenidConnectProviderContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/openidconnectprovider/method_listsecrets.go b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/method_listsecrets.go new file mode 100644 index 00000000000..39b0cbb3857 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/method_listsecrets.go @@ -0,0 +1,55 @@ +package openidconnectprovider + +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 ListSecretsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ClientSecretContract +} + +// ListSecrets ... +func (c OpenidConnectProviderClient) ListSecrets(ctx context.Context, id OpenidConnectProviderId) (result ListSecretsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listSecrets", 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 ClientSecretContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/openidconnectprovider/method_update.go b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/method_update.go new file mode 100644 index 00000000000..fc095d745c7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/method_update.go @@ -0,0 +1,87 @@ +package openidconnectprovider + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *OpenidConnectProviderContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c OpenidConnectProviderClient) Update(ctx context.Context, id OpenidConnectProviderId, input OpenidConnectProviderUpdateContract, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 OpenidConnectProviderContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/openidconnectprovider/model_clientsecretcontract.go b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/model_clientsecretcontract.go new file mode 100644 index 00000000000..c557135ce96 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/model_clientsecretcontract.go @@ -0,0 +1,8 @@ +package openidconnectprovider + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClientSecretContract struct { + ClientSecret *string `json:"clientSecret,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/openidconnectprovider/model_openidconnectprovidercontract.go b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/model_openidconnectprovidercontract.go new file mode 100644 index 00000000000..a49188977ed --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/model_openidconnectprovidercontract.go @@ -0,0 +1,11 @@ +package openidconnectprovider + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OpenidConnectProviderContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *OpenidConnectProviderContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/openidconnectprovider/model_openidconnectprovidercontractproperties.go b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/model_openidconnectprovidercontractproperties.go new file mode 100644 index 00000000000..518c9d69a48 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/model_openidconnectprovidercontractproperties.go @@ -0,0 +1,14 @@ +package openidconnectprovider + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OpenidConnectProviderContractProperties struct { + ClientId string `json:"clientId"` + ClientSecret *string `json:"clientSecret,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName string `json:"displayName"` + MetadataEndpoint string `json:"metadataEndpoint"` + UseInApiDocumentation *bool `json:"useInApiDocumentation,omitempty"` + UseInTestConsole *bool `json:"useInTestConsole,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/openidconnectprovider/model_openidconnectproviderupdatecontract.go b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/model_openidconnectproviderupdatecontract.go new file mode 100644 index 00000000000..bdac084e19d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/model_openidconnectproviderupdatecontract.go @@ -0,0 +1,8 @@ +package openidconnectprovider + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OpenidConnectProviderUpdateContract struct { + Properties *OpenidConnectProviderUpdateContractProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/openidconnectprovider/model_openidconnectproviderupdatecontractproperties.go b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/model_openidconnectproviderupdatecontractproperties.go new file mode 100644 index 00000000000..52c0f2170ee --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/model_openidconnectproviderupdatecontractproperties.go @@ -0,0 +1,14 @@ +package openidconnectprovider + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OpenidConnectProviderUpdateContractProperties struct { + ClientId *string `json:"clientId,omitempty"` + ClientSecret *string `json:"clientSecret,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + MetadataEndpoint *string `json:"metadataEndpoint,omitempty"` + UseInApiDocumentation *bool `json:"useInApiDocumentation,omitempty"` + UseInTestConsole *bool `json:"useInTestConsole,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/openidconnectprovider/predicates.go b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/predicates.go new file mode 100644 index 00000000000..9a85ff23a16 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/predicates.go @@ -0,0 +1,27 @@ +package openidconnectprovider + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OpenidConnectProviderContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p OpenidConnectProviderContractOperationPredicate) Matches(input OpenidConnectProviderContract) 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/apimanagement/2024-05-01/openidconnectprovider/version.go b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/version.go new file mode 100644 index 00000000000..5056cdad935 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/openidconnectprovider/version.go @@ -0,0 +1,12 @@ +package openidconnectprovider + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/openidconnectprovider/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/README.md b/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/README.md new file mode 100644 index 00000000000..1a0fccec578 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints` Documentation + +The `outboundnetworkdependenciesendpoints` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints" +``` + + +### Client Initialization + +```go +client := outboundnetworkdependenciesendpoints.NewOutboundNetworkDependenciesEndpointsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `OutboundNetworkDependenciesEndpointsClient.ListByService` + +```go +ctx := context.TODO() +id := outboundnetworkdependenciesendpoints.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id)` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/client.go b/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/client.go new file mode 100644 index 00000000000..d5ab391daa6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/client.go @@ -0,0 +1,26 @@ +package outboundnetworkdependenciesendpoints + +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 OutboundNetworkDependenciesEndpointsClient struct { + Client *resourcemanager.Client +} + +func NewOutboundNetworkDependenciesEndpointsClientWithBaseURI(sdkApi sdkEnv.Api) (*OutboundNetworkDependenciesEndpointsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "outboundnetworkdependenciesendpoints", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating OutboundNetworkDependenciesEndpointsClient: %+v", err) + } + + return &OutboundNetworkDependenciesEndpointsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/id_service.go b/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/id_service.go new file mode 100644 index 00000000000..a2a71284e3f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/id_service.go @@ -0,0 +1,130 @@ +package outboundnetworkdependenciesendpoints + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/id_service_test.go b/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/id_service_test.go new file mode 100644 index 00000000000..175a7567b29 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/id_service_test.go @@ -0,0 +1,282 @@ +package outboundnetworkdependenciesendpoints + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/method_listbyservice.go new file mode 100644 index 00000000000..5857b50c144 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/method_listbyservice.go @@ -0,0 +1,105 @@ +package outboundnetworkdependenciesendpoints + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]OutboundEnvironmentEndpoint +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []OutboundEnvironmentEndpoint +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c OutboundNetworkDependenciesEndpointsClient) ListByService(ctx context.Context, id ServiceId) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/outboundNetworkDependenciesEndpoints", 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 *[]OutboundEnvironmentEndpoint `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c OutboundNetworkDependenciesEndpointsClient) ListByServiceComplete(ctx context.Context, id ServiceId) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, OutboundEnvironmentEndpointOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c OutboundNetworkDependenciesEndpointsClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, predicate OutboundEnvironmentEndpointOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]OutboundEnvironmentEndpoint, 0) + + resp, err := c.ListByService(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/model_endpointdependency.go b/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/model_endpointdependency.go new file mode 100644 index 00000000000..81feeb21f76 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/model_endpointdependency.go @@ -0,0 +1,9 @@ +package outboundnetworkdependenciesendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EndpointDependency struct { + DomainName *string `json:"domainName,omitempty"` + EndpointDetails *[]EndpointDetail `json:"endpointDetails,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/model_endpointdetail.go b/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/model_endpointdetail.go new file mode 100644 index 00000000000..03206c7f5e4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/model_endpointdetail.go @@ -0,0 +1,9 @@ +package outboundnetworkdependenciesendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EndpointDetail struct { + Port *int64 `json:"port,omitempty"` + Region *string `json:"region,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/model_outboundenvironmentendpoint.go b/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/model_outboundenvironmentendpoint.go new file mode 100644 index 00000000000..d481f55194e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/model_outboundenvironmentendpoint.go @@ -0,0 +1,9 @@ +package outboundnetworkdependenciesendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OutboundEnvironmentEndpoint struct { + Category *string `json:"category,omitempty"` + Endpoints *[]EndpointDependency `json:"endpoints,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/predicates.go b/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/predicates.go new file mode 100644 index 00000000000..1e053fe820f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/predicates.go @@ -0,0 +1,17 @@ +package outboundnetworkdependenciesendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OutboundEnvironmentEndpointOperationPredicate struct { + Category *string +} + +func (p OutboundEnvironmentEndpointOperationPredicate) Matches(input OutboundEnvironmentEndpoint) bool { + + if p.Category != nil && (input.Category == nil || *p.Category != *input.Category) { + return false + } + + return true +} diff --git a/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/version.go b/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/version.go new file mode 100644 index 00000000000..642b15db3ac --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/outboundnetworkdependenciesendpoints/version.go @@ -0,0 +1,12 @@ +package outboundnetworkdependenciesendpoints + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/outboundnetworkdependenciesendpoints/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/README.md b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/README.md new file mode 100644 index 00000000000..cedac9d697e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/performconnectivitycheck` Documentation + +The `performconnectivitycheck` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/performconnectivitycheck" +``` + + +### Client Initialization + +```go +client := performconnectivitycheck.NewPerformConnectivityCheckClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PerformConnectivityCheckClient.Async` + +```go +ctx := context.TODO() +id := performconnectivitycheck.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +payload := performconnectivitycheck.ConnectivityCheckRequest{ + // ... +} + + +if err := client.AsyncThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/client.go b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/client.go new file mode 100644 index 00000000000..a491979992c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/client.go @@ -0,0 +1,26 @@ +package performconnectivitycheck + +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 PerformConnectivityCheckClient struct { + Client *resourcemanager.Client +} + +func NewPerformConnectivityCheckClientWithBaseURI(sdkApi sdkEnv.Api) (*PerformConnectivityCheckClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "performconnectivitycheck", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PerformConnectivityCheckClient: %+v", err) + } + + return &PerformConnectivityCheckClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/constants.go b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/constants.go new file mode 100644 index 00000000000..df0ed03802b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/constants.go @@ -0,0 +1,327 @@ +package performconnectivitycheck + +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 ConnectionStatus string + +const ( + ConnectionStatusConnected ConnectionStatus = "Connected" + ConnectionStatusDegraded ConnectionStatus = "Degraded" + ConnectionStatusDisconnected ConnectionStatus = "Disconnected" + ConnectionStatusUnknown ConnectionStatus = "Unknown" +) + +func PossibleValuesForConnectionStatus() []string { + return []string{ + string(ConnectionStatusConnected), + string(ConnectionStatusDegraded), + string(ConnectionStatusDisconnected), + string(ConnectionStatusUnknown), + } +} + +func (s *ConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseConnectionStatus(input string) (*ConnectionStatus, error) { + vals := map[string]ConnectionStatus{ + "connected": ConnectionStatusConnected, + "degraded": ConnectionStatusDegraded, + "disconnected": ConnectionStatusDisconnected, + "unknown": ConnectionStatusUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConnectionStatus(input) + return &out, nil +} + +type ConnectivityCheckProtocol string + +const ( + ConnectivityCheckProtocolHTTP ConnectivityCheckProtocol = "HTTP" + ConnectivityCheckProtocolHTTPS ConnectivityCheckProtocol = "HTTPS" + ConnectivityCheckProtocolTCP ConnectivityCheckProtocol = "TCP" +) + +func PossibleValuesForConnectivityCheckProtocol() []string { + return []string{ + string(ConnectivityCheckProtocolHTTP), + string(ConnectivityCheckProtocolHTTPS), + string(ConnectivityCheckProtocolTCP), + } +} + +func (s *ConnectivityCheckProtocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConnectivityCheckProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseConnectivityCheckProtocol(input string) (*ConnectivityCheckProtocol, error) { + vals := map[string]ConnectivityCheckProtocol{ + "http": ConnectivityCheckProtocolHTTP, + "https": ConnectivityCheckProtocolHTTPS, + "tcp": ConnectivityCheckProtocolTCP, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConnectivityCheckProtocol(input) + return &out, nil +} + +type IssueType string + +const ( + IssueTypeAgentStopped IssueType = "AgentStopped" + IssueTypeDnsResolution IssueType = "DnsResolution" + IssueTypeGuestFirewall IssueType = "GuestFirewall" + IssueTypeNetworkSecurityRule IssueType = "NetworkSecurityRule" + IssueTypePlatform IssueType = "Platform" + IssueTypePortThrottled IssueType = "PortThrottled" + IssueTypeSocketBind IssueType = "SocketBind" + IssueTypeUnknown IssueType = "Unknown" + IssueTypeUserDefinedRoute IssueType = "UserDefinedRoute" +) + +func PossibleValuesForIssueType() []string { + return []string{ + string(IssueTypeAgentStopped), + string(IssueTypeDnsResolution), + string(IssueTypeGuestFirewall), + string(IssueTypeNetworkSecurityRule), + string(IssueTypePlatform), + string(IssueTypePortThrottled), + string(IssueTypeSocketBind), + string(IssueTypeUnknown), + string(IssueTypeUserDefinedRoute), + } +} + +func (s *IssueType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIssueType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIssueType(input string) (*IssueType, error) { + vals := map[string]IssueType{ + "agentstopped": IssueTypeAgentStopped, + "dnsresolution": IssueTypeDnsResolution, + "guestfirewall": IssueTypeGuestFirewall, + "networksecurityrule": IssueTypeNetworkSecurityRule, + "platform": IssueTypePlatform, + "portthrottled": IssueTypePortThrottled, + "socketbind": IssueTypeSocketBind, + "unknown": IssueTypeUnknown, + "userdefinedroute": IssueTypeUserDefinedRoute, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IssueType(input) + return &out, nil +} + +type Method string + +const ( + MethodGET Method = "GET" + MethodPOST Method = "POST" +) + +func PossibleValuesForMethod() []string { + return []string{ + string(MethodGET), + string(MethodPOST), + } +} + +func (s *Method) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMethod(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMethod(input string) (*Method, error) { + vals := map[string]Method{ + "get": MethodGET, + "post": MethodPOST, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Method(input) + return &out, nil +} + +type Origin string + +const ( + OriginInbound Origin = "Inbound" + OriginLocal Origin = "Local" + OriginOutbound Origin = "Outbound" +) + +func PossibleValuesForOrigin() []string { + return []string{ + string(OriginInbound), + string(OriginLocal), + string(OriginOutbound), + } +} + +func (s *Origin) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOrigin(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOrigin(input string) (*Origin, error) { + vals := map[string]Origin{ + "inbound": OriginInbound, + "local": OriginLocal, + "outbound": OriginOutbound, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Origin(input) + return &out, nil +} + +type PreferredIPVersion string + +const ( + PreferredIPVersionIPvFour PreferredIPVersion = "IPv4" +) + +func PossibleValuesForPreferredIPVersion() []string { + return []string{ + string(PreferredIPVersionIPvFour), + } +} + +func (s *PreferredIPVersion) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePreferredIPVersion(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePreferredIPVersion(input string) (*PreferredIPVersion, error) { + vals := map[string]PreferredIPVersion{ + "ipv4": PreferredIPVersionIPvFour, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PreferredIPVersion(input) + return &out, nil +} + +type Severity string + +const ( + SeverityError Severity = "Error" + SeverityWarning Severity = "Warning" +) + +func PossibleValuesForSeverity() []string { + return []string{ + string(SeverityError), + string(SeverityWarning), + } +} + +func (s *Severity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSeverity(input string) (*Severity, error) { + vals := map[string]Severity{ + "error": SeverityError, + "warning": SeverityWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Severity(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/id_service.go b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/id_service.go new file mode 100644 index 00000000000..6a34f7693f4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/id_service.go @@ -0,0 +1,130 @@ +package performconnectivitycheck + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/id_service_test.go b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/id_service_test.go new file mode 100644 index 00000000000..11b9caadb8a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/id_service_test.go @@ -0,0 +1,282 @@ +package performconnectivitycheck + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/method_async.go b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/method_async.go new file mode 100644 index 00000000000..9eb83acfea4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/method_async.go @@ -0,0 +1,75 @@ +package performconnectivitycheck + +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 AsyncOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ConnectivityCheckResponse +} + +// Async ... +func (c PerformConnectivityCheckClient) Async(ctx context.Context, id ServiceId, input ConnectivityCheckRequest) (result AsyncOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/connectivityCheck", 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 +} + +// AsyncThenPoll performs Async then polls until it's completed +func (c PerformConnectivityCheckClient) AsyncThenPoll(ctx context.Context, id ServiceId, input ConnectivityCheckRequest) error { + result, err := c.Async(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Async: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Async: %+v", err) + } + + return nil +} diff --git a/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_connectivitycheckrequest.go b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_connectivitycheckrequest.go new file mode 100644 index 00000000000..9844591bf61 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_connectivitycheckrequest.go @@ -0,0 +1,12 @@ +package performconnectivitycheck + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectivityCheckRequest struct { + Destination ConnectivityCheckRequestDestination `json:"destination"` + PreferredIPVersion *PreferredIPVersion `json:"preferredIPVersion,omitempty"` + Protocol *ConnectivityCheckProtocol `json:"protocol,omitempty"` + ProtocolConfiguration *ConnectivityCheckRequestProtocolConfiguration `json:"protocolConfiguration,omitempty"` + Source ConnectivityCheckRequestSource `json:"source"` +} diff --git a/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_connectivitycheckrequestdestination.go b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_connectivitycheckrequestdestination.go new file mode 100644 index 00000000000..80273c1115f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_connectivitycheckrequestdestination.go @@ -0,0 +1,9 @@ +package performconnectivitycheck + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectivityCheckRequestDestination struct { + Address string `json:"address"` + Port int64 `json:"port"` +} diff --git a/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_connectivitycheckrequestprotocolconfiguration.go b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_connectivitycheckrequestprotocolconfiguration.go new file mode 100644 index 00000000000..8a129128ee7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_connectivitycheckrequestprotocolconfiguration.go @@ -0,0 +1,8 @@ +package performconnectivitycheck + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectivityCheckRequestProtocolConfiguration struct { + HTTPConfiguration *ConnectivityCheckRequestProtocolConfigurationHTTPConfiguration `json:"HTTPConfiguration,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_connectivitycheckrequestprotocolconfigurationhttpconfiguration.go b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_connectivitycheckrequestprotocolconfigurationhttpconfiguration.go new file mode 100644 index 00000000000..f0c42c6f3f5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_connectivitycheckrequestprotocolconfigurationhttpconfiguration.go @@ -0,0 +1,10 @@ +package performconnectivitycheck + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectivityCheckRequestProtocolConfigurationHTTPConfiguration struct { + Headers *[]HTTPHeader `json:"headers,omitempty"` + Method *Method `json:"method,omitempty"` + ValidStatusCodes *[]int64 `json:"validStatusCodes,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_connectivitycheckrequestsource.go b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_connectivitycheckrequestsource.go new file mode 100644 index 00000000000..57a6bfeef70 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_connectivitycheckrequestsource.go @@ -0,0 +1,9 @@ +package performconnectivitycheck + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectivityCheckRequestSource struct { + Instance *int64 `json:"instance,omitempty"` + Region string `json:"region"` +} diff --git a/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_connectivitycheckresponse.go b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_connectivitycheckresponse.go new file mode 100644 index 00000000000..e6dbe86de58 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_connectivitycheckresponse.go @@ -0,0 +1,14 @@ +package performconnectivitycheck + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectivityCheckResponse struct { + AvgLatencyInMs *int64 `json:"avgLatencyInMs,omitempty"` + ConnectionStatus *ConnectionStatus `json:"connectionStatus,omitempty"` + Hops *[]ConnectivityHop `json:"hops,omitempty"` + MaxLatencyInMs *int64 `json:"maxLatencyInMs,omitempty"` + MinLatencyInMs *int64 `json:"minLatencyInMs,omitempty"` + ProbesFailed *int64 `json:"probesFailed,omitempty"` + ProbesSent *int64 `json:"probesSent,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_connectivityhop.go b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_connectivityhop.go new file mode 100644 index 00000000000..5f01d535baa --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_connectivityhop.go @@ -0,0 +1,13 @@ +package performconnectivitycheck + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectivityHop struct { + Address *string `json:"address,omitempty"` + Id *string `json:"id,omitempty"` + Issues *[]ConnectivityIssue `json:"issues,omitempty"` + NextHopIds *[]string `json:"nextHopIds,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_connectivityissue.go b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_connectivityissue.go new file mode 100644 index 00000000000..da14ddfa006 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_connectivityissue.go @@ -0,0 +1,11 @@ +package performconnectivitycheck + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectivityIssue struct { + Context *[]map[string]string `json:"context,omitempty"` + Origin *Origin `json:"origin,omitempty"` + Severity *Severity `json:"severity,omitempty"` + Type *IssueType `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_httpheader.go b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_httpheader.go new file mode 100644 index 00000000000..3f74586de8b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/model_httpheader.go @@ -0,0 +1,9 @@ +package performconnectivitycheck + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HTTPHeader struct { + Name string `json:"name"` + Value string `json:"value"` +} diff --git a/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/version.go b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/version.go new file mode 100644 index 00000000000..8479466ba9c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/performconnectivitycheck/version.go @@ -0,0 +1,12 @@ +package performconnectivitycheck + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/performconnectivitycheck/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/policy/README.md b/resource-manager/apimanagement/2024-05-01/policy/README.md new file mode 100644 index 00000000000..b40ac23c024 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policy/README.md @@ -0,0 +1,106 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policy` Documentation + +The `policy` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policy" +``` + + +### Client Initialization + +```go +client := policy.NewPolicyClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PolicyClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := policy.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +payload := policy.PolicyContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, policy.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PolicyClient.Delete` + +```go +ctx := context.TODO() +id := policy.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +read, err := client.Delete(ctx, id, policy.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PolicyClient.Get` + +```go +ctx := context.TODO() +id := policy.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +read, err := client.Get(ctx, id, policy.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PolicyClient.GetEntityTag` + +```go +ctx := context.TODO() +id := policy.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PolicyClient.ListByService` + +```go +ctx := context.TODO() +id := policy.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id)` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/policy/client.go b/resource-manager/apimanagement/2024-05-01/policy/client.go new file mode 100644 index 00000000000..216d1f1ff33 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policy/client.go @@ -0,0 +1,26 @@ +package policy + +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 PolicyClient struct { + Client *resourcemanager.Client +} + +func NewPolicyClientWithBaseURI(sdkApi sdkEnv.Api) (*PolicyClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "policy", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PolicyClient: %+v", err) + } + + return &PolicyClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/policy/constants.go b/resource-manager/apimanagement/2024-05-01/policy/constants.go new file mode 100644 index 00000000000..10a4650a395 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policy/constants.go @@ -0,0 +1,98 @@ +package policy + +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 PolicyContentFormat string + +const ( + PolicyContentFormatRawxml PolicyContentFormat = "rawxml" + PolicyContentFormatRawxmlNegativelink PolicyContentFormat = "rawxml-link" + PolicyContentFormatXml PolicyContentFormat = "xml" + PolicyContentFormatXmlNegativelink PolicyContentFormat = "xml-link" +) + +func PossibleValuesForPolicyContentFormat() []string { + return []string{ + string(PolicyContentFormatRawxml), + string(PolicyContentFormatRawxmlNegativelink), + string(PolicyContentFormatXml), + string(PolicyContentFormatXmlNegativelink), + } +} + +func (s *PolicyContentFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePolicyContentFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePolicyContentFormat(input string) (*PolicyContentFormat, error) { + vals := map[string]PolicyContentFormat{ + "rawxml": PolicyContentFormatRawxml, + "rawxml-link": PolicyContentFormatRawxmlNegativelink, + "xml": PolicyContentFormatXml, + "xml-link": PolicyContentFormatXmlNegativelink, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyContentFormat(input) + return &out, nil +} + +type PolicyExportFormat string + +const ( + PolicyExportFormatRawxml PolicyExportFormat = "rawxml" + PolicyExportFormatXml PolicyExportFormat = "xml" +) + +func PossibleValuesForPolicyExportFormat() []string { + return []string{ + string(PolicyExportFormatRawxml), + string(PolicyExportFormatXml), + } +} + +func (s *PolicyExportFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePolicyExportFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePolicyExportFormat(input string) (*PolicyExportFormat, error) { + vals := map[string]PolicyExportFormat{ + "rawxml": PolicyExportFormatRawxml, + "xml": PolicyExportFormatXml, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyExportFormat(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/policy/id_service.go b/resource-manager/apimanagement/2024-05-01/policy/id_service.go new file mode 100644 index 00000000000..509f96c5a3f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policy/id_service.go @@ -0,0 +1,130 @@ +package policy + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/policy/id_service_test.go b/resource-manager/apimanagement/2024-05-01/policy/id_service_test.go new file mode 100644 index 00000000000..c920de26864 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policy/id_service_test.go @@ -0,0 +1,282 @@ +package policy + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/policy/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/policy/method_createorupdate.go new file mode 100644 index 00000000000..3bfe1519731 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policy/method_createorupdate.go @@ -0,0 +1,88 @@ +package policy + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c PolicyClient) CreateOrUpdate(ctx context.Context, id ServiceId, input PolicyContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", 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 PolicyContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/policy/method_delete.go b/resource-manager/apimanagement/2024-05-01/policy/method_delete.go new file mode 100644 index 00000000000..4b39d1a4a2d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policy/method_delete.go @@ -0,0 +1,76 @@ +package policy + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c PolicyClient) Delete(ctx context.Context, id ServiceId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/policy/method_get.go b/resource-manager/apimanagement/2024-05-01/policy/method_get.go new file mode 100644 index 00000000000..5a9a428f5ec --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policy/method_get.go @@ -0,0 +1,83 @@ +package policy + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyContract +} + +type GetOperationOptions struct { + Format *PolicyExportFormat +} + +func DefaultGetOperationOptions() GetOperationOptions { + return GetOperationOptions{} +} + +func (o GetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o GetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o GetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Format != nil { + out.Append("format", fmt.Sprintf("%v", *o.Format)) + } + return &out +} + +// Get ... +func (c PolicyClient) Get(ctx context.Context, id ServiceId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", 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 PolicyContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/policy/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/policy/method_getentitytag.go new file mode 100644 index 00000000000..d8575a5f4ca --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policy/method_getentitytag.go @@ -0,0 +1,47 @@ +package policy + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c PolicyClient) GetEntityTag(ctx context.Context, id ServiceId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: fmt.Sprintf("%s/policies/policy", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/policy/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/policy/method_listbyservice.go new file mode 100644 index 00000000000..9a51b88a353 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policy/method_listbyservice.go @@ -0,0 +1,105 @@ +package policy + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PolicyContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []PolicyContract +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c PolicyClient) ListByService(ctx context.Context, id ServiceId) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/policies", 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 *[]PolicyContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c PolicyClient) ListByServiceComplete(ctx context.Context, id ServiceId) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, PolicyContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PolicyClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, predicate PolicyContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]PolicyContract, 0) + + resp, err := c.ListByService(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/policy/model_policycontract.go b/resource-manager/apimanagement/2024-05-01/policy/model_policycontract.go new file mode 100644 index 00000000000..72047b56ce6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policy/model_policycontract.go @@ -0,0 +1,11 @@ +package policy + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PolicyContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/policy/model_policycontractproperties.go b/resource-manager/apimanagement/2024-05-01/policy/model_policycontractproperties.go new file mode 100644 index 00000000000..a74af523117 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policy/model_policycontractproperties.go @@ -0,0 +1,9 @@ +package policy + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyContractProperties struct { + Format *PolicyContentFormat `json:"format,omitempty"` + Value string `json:"value"` +} diff --git a/resource-manager/apimanagement/2024-05-01/policy/predicates.go b/resource-manager/apimanagement/2024-05-01/policy/predicates.go new file mode 100644 index 00000000000..ea09e353d25 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policy/predicates.go @@ -0,0 +1,27 @@ +package policy + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PolicyContractOperationPredicate) Matches(input PolicyContract) 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/apimanagement/2024-05-01/policy/version.go b/resource-manager/apimanagement/2024-05-01/policy/version.go new file mode 100644 index 00000000000..1f2610f5094 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policy/version.go @@ -0,0 +1,12 @@ +package policy + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/policy/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/policydescription/README.md b/resource-manager/apimanagement/2024-05-01/policydescription/README.md new file mode 100644 index 00000000000..b5d36d886ad --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policydescription/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policydescription` Documentation + +The `policydescription` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policydescription" +``` + + +### Client Initialization + +```go +client := policydescription.NewPolicyDescriptionClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PolicyDescriptionClient.ListByService` + +```go +ctx := context.TODO() +id := policydescription.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +read, err := client.ListByService(ctx, id, policydescription.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/policydescription/client.go b/resource-manager/apimanagement/2024-05-01/policydescription/client.go new file mode 100644 index 00000000000..70daacb1cfc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policydescription/client.go @@ -0,0 +1,26 @@ +package policydescription + +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 PolicyDescriptionClient struct { + Client *resourcemanager.Client +} + +func NewPolicyDescriptionClientWithBaseURI(sdkApi sdkEnv.Api) (*PolicyDescriptionClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "policydescription", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PolicyDescriptionClient: %+v", err) + } + + return &PolicyDescriptionClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/policydescription/constants.go b/resource-manager/apimanagement/2024-05-01/policydescription/constants.go new file mode 100644 index 00000000000..be5c274580c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policydescription/constants.go @@ -0,0 +1,60 @@ +package policydescription + +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 PolicyScopeContract string + +const ( + PolicyScopeContractAll PolicyScopeContract = "All" + PolicyScopeContractApi PolicyScopeContract = "Api" + PolicyScopeContractOperation PolicyScopeContract = "Operation" + PolicyScopeContractProduct PolicyScopeContract = "Product" + PolicyScopeContractTenant PolicyScopeContract = "Tenant" +) + +func PossibleValuesForPolicyScopeContract() []string { + return []string{ + string(PolicyScopeContractAll), + string(PolicyScopeContractApi), + string(PolicyScopeContractOperation), + string(PolicyScopeContractProduct), + string(PolicyScopeContractTenant), + } +} + +func (s *PolicyScopeContract) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePolicyScopeContract(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePolicyScopeContract(input string) (*PolicyScopeContract, error) { + vals := map[string]PolicyScopeContract{ + "all": PolicyScopeContractAll, + "api": PolicyScopeContractApi, + "operation": PolicyScopeContractOperation, + "product": PolicyScopeContractProduct, + "tenant": PolicyScopeContractTenant, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyScopeContract(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/policydescription/id_service.go b/resource-manager/apimanagement/2024-05-01/policydescription/id_service.go new file mode 100644 index 00000000000..41cef29b463 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policydescription/id_service.go @@ -0,0 +1,130 @@ +package policydescription + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/policydescription/id_service_test.go b/resource-manager/apimanagement/2024-05-01/policydescription/id_service_test.go new file mode 100644 index 00000000000..baf5c9fff0d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policydescription/id_service_test.go @@ -0,0 +1,282 @@ +package policydescription + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/policydescription/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/policydescription/method_listbyservice.go new file mode 100644 index 00000000000..cb12120f377 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policydescription/method_listbyservice.go @@ -0,0 +1,83 @@ +package policydescription + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyDescriptionCollection +} + +type ListByServiceOperationOptions struct { + Scope *PolicyScopeContract +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Scope != nil { + out.Append("scope", fmt.Sprintf("%v", *o.Scope)) + } + return &out +} + +// ListByService ... +func (c PolicyDescriptionClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/policyDescriptions", 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 PolicyDescriptionCollection + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/policydescription/model_policydescriptioncollection.go b/resource-manager/apimanagement/2024-05-01/policydescription/model_policydescriptioncollection.go new file mode 100644 index 00000000000..031c075eb90 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policydescription/model_policydescriptioncollection.go @@ -0,0 +1,9 @@ +package policydescription + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyDescriptionCollection struct { + Count *int64 `json:"count,omitempty"` + Value *[]PolicyDescriptionContract `json:"value,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/policydescription/model_policydescriptioncontract.go b/resource-manager/apimanagement/2024-05-01/policydescription/model_policydescriptioncontract.go new file mode 100644 index 00000000000..0df79fc1d68 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policydescription/model_policydescriptioncontract.go @@ -0,0 +1,11 @@ +package policydescription + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyDescriptionContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PolicyDescriptionContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/policydescription/model_policydescriptioncontractproperties.go b/resource-manager/apimanagement/2024-05-01/policydescription/model_policydescriptioncontractproperties.go new file mode 100644 index 00000000000..0b46ff5075b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policydescription/model_policydescriptioncontractproperties.go @@ -0,0 +1,9 @@ +package policydescription + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyDescriptionContractProperties struct { + Description *string `json:"description,omitempty"` + Scope *int64 `json:"scope,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/policydescription/version.go b/resource-manager/apimanagement/2024-05-01/policydescription/version.go new file mode 100644 index 00000000000..fce2d40c011 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policydescription/version.go @@ -0,0 +1,12 @@ +package policydescription + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/policydescription/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/README.md b/resource-manager/apimanagement/2024-05-01/policyfragment/README.md new file mode 100644 index 00000000000..921818c3d2a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/README.md @@ -0,0 +1,218 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment` Documentation + +The `policyfragment` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment" +``` + + +### Client Initialization + +```go +client := policyfragment.NewPolicyFragmentClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PolicyFragmentClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := policyfragment.NewPolicyFragmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "policyFragmentValue") + +payload := policyfragment.PolicyFragmentContract{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload, policyfragment.DefaultCreateOrUpdateOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `PolicyFragmentClient.Delete` + +```go +ctx := context.TODO() +id := policyfragment.NewPolicyFragmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "policyFragmentValue") + +read, err := client.Delete(ctx, id, policyfragment.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PolicyFragmentClient.Get` + +```go +ctx := context.TODO() +id := policyfragment.NewPolicyFragmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "policyFragmentValue") + +read, err := client.Get(ctx, id, policyfragment.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PolicyFragmentClient.GetEntityTag` + +```go +ctx := context.TODO() +id := policyfragment.NewPolicyFragmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "policyFragmentValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PolicyFragmentClient.ListByService` + +```go +ctx := context.TODO() +id := policyfragment.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, policyfragment.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, policyfragment.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PolicyFragmentClient.ListReferences` + +```go +ctx := context.TODO() +id := policyfragment.NewPolicyFragmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "policyFragmentValue") + +// alternatively `client.ListReferences(ctx, id, policyfragment.DefaultListReferencesOperationOptions())` can be used to do batched pagination +items, err := client.ListReferencesComplete(ctx, id, policyfragment.DefaultListReferencesOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PolicyFragmentClient.WorkspacePolicyFragmentCreateOrUpdate` + +```go +ctx := context.TODO() +id := policyfragment.NewWorkspacePolicyFragmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "policyFragmentValue") + +payload := policyfragment.PolicyFragmentContract{ + // ... +} + + +if err := client.WorkspacePolicyFragmentCreateOrUpdateThenPoll(ctx, id, payload, policyfragment.DefaultWorkspacePolicyFragmentCreateOrUpdateOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `PolicyFragmentClient.WorkspacePolicyFragmentDelete` + +```go +ctx := context.TODO() +id := policyfragment.NewWorkspacePolicyFragmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "policyFragmentValue") + +read, err := client.WorkspacePolicyFragmentDelete(ctx, id, policyfragment.DefaultWorkspacePolicyFragmentDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PolicyFragmentClient.WorkspacePolicyFragmentGet` + +```go +ctx := context.TODO() +id := policyfragment.NewWorkspacePolicyFragmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "policyFragmentValue") + +read, err := client.WorkspacePolicyFragmentGet(ctx, id, policyfragment.DefaultWorkspacePolicyFragmentGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PolicyFragmentClient.WorkspacePolicyFragmentGetEntityTag` + +```go +ctx := context.TODO() +id := policyfragment.NewWorkspacePolicyFragmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "policyFragmentValue") + +read, err := client.WorkspacePolicyFragmentGetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PolicyFragmentClient.WorkspacePolicyFragmentListByService` + +```go +ctx := context.TODO() +id := policyfragment.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +// alternatively `client.WorkspacePolicyFragmentListByService(ctx, id, policyfragment.DefaultWorkspacePolicyFragmentListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.WorkspacePolicyFragmentListByServiceComplete(ctx, id, policyfragment.DefaultWorkspacePolicyFragmentListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PolicyFragmentClient.WorkspacePolicyFragmentListReferences` + +```go +ctx := context.TODO() +id := policyfragment.NewWorkspacePolicyFragmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "policyFragmentValue") + +// alternatively `client.WorkspacePolicyFragmentListReferences(ctx, id, policyfragment.DefaultWorkspacePolicyFragmentListReferencesOperationOptions())` can be used to do batched pagination +items, err := client.WorkspacePolicyFragmentListReferencesComplete(ctx, id, policyfragment.DefaultWorkspacePolicyFragmentListReferencesOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/client.go b/resource-manager/apimanagement/2024-05-01/policyfragment/client.go new file mode 100644 index 00000000000..3dbe1d43bb7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/client.go @@ -0,0 +1,26 @@ +package policyfragment + +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 PolicyFragmentClient struct { + Client *resourcemanager.Client +} + +func NewPolicyFragmentClientWithBaseURI(sdkApi sdkEnv.Api) (*PolicyFragmentClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "policyfragment", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PolicyFragmentClient: %+v", err) + } + + return &PolicyFragmentClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/constants.go b/resource-manager/apimanagement/2024-05-01/policyfragment/constants.go new file mode 100644 index 00000000000..60aec2160bc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/constants.go @@ -0,0 +1,51 @@ +package policyfragment + +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 PolicyFragmentContentFormat string + +const ( + PolicyFragmentContentFormatRawxml PolicyFragmentContentFormat = "rawxml" + PolicyFragmentContentFormatXml PolicyFragmentContentFormat = "xml" +) + +func PossibleValuesForPolicyFragmentContentFormat() []string { + return []string{ + string(PolicyFragmentContentFormatRawxml), + string(PolicyFragmentContentFormatXml), + } +} + +func (s *PolicyFragmentContentFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePolicyFragmentContentFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePolicyFragmentContentFormat(input string) (*PolicyFragmentContentFormat, error) { + vals := map[string]PolicyFragmentContentFormat{ + "rawxml": PolicyFragmentContentFormatRawxml, + "xml": PolicyFragmentContentFormatXml, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyFragmentContentFormat(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/id_policyfragment.go b/resource-manager/apimanagement/2024-05-01/policyfragment/id_policyfragment.go new file mode 100644 index 00000000000..3737ed73101 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/id_policyfragment.go @@ -0,0 +1,139 @@ +package policyfragment + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PolicyFragmentId{}) +} + +var _ resourceids.ResourceId = &PolicyFragmentId{} + +// PolicyFragmentId is a struct representing the Resource ID for a Policy Fragment +type PolicyFragmentId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + PolicyFragmentName string +} + +// NewPolicyFragmentID returns a new PolicyFragmentId struct +func NewPolicyFragmentID(subscriptionId string, resourceGroupName string, serviceName string, policyFragmentName string) PolicyFragmentId { + return PolicyFragmentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + PolicyFragmentName: policyFragmentName, + } +} + +// ParsePolicyFragmentID parses 'input' into a PolicyFragmentId +func ParsePolicyFragmentID(input string) (*PolicyFragmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&PolicyFragmentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PolicyFragmentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePolicyFragmentIDInsensitively parses 'input' case-insensitively into a PolicyFragmentId +// note: this method should only be used for API response data and not user input +func ParsePolicyFragmentIDInsensitively(input string) (*PolicyFragmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&PolicyFragmentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PolicyFragmentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PolicyFragmentId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.PolicyFragmentName, ok = input.Parsed["policyFragmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "policyFragmentName", input) + } + + return nil +} + +// ValidatePolicyFragmentID checks that 'input' can be parsed as a Policy Fragment ID +func ValidatePolicyFragmentID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePolicyFragmentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Policy Fragment ID +func (id PolicyFragmentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/policyFragments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.PolicyFragmentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Policy Fragment ID +func (id PolicyFragmentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticPolicyFragments", "policyFragments", "policyFragments"), + resourceids.UserSpecifiedSegment("policyFragmentName", "policyFragmentValue"), + } +} + +// String returns a human-readable description of this Policy Fragment ID +func (id PolicyFragmentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Policy Fragment Name: %q", id.PolicyFragmentName), + } + return fmt.Sprintf("Policy Fragment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/id_policyfragment_test.go b/resource-manager/apimanagement/2024-05-01/policyfragment/id_policyfragment_test.go new file mode 100644 index 00000000000..138597ae80c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/id_policyfragment_test.go @@ -0,0 +1,327 @@ +package policyfragment + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PolicyFragmentId{} + +func TestNewPolicyFragmentID(t *testing.T) { + id := NewPolicyFragmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "policyFragmentValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.PolicyFragmentName != "policyFragmentValue" { + t.Fatalf("Expected %q but got %q for Segment 'PolicyFragmentName'", id.PolicyFragmentName, "policyFragmentValue") + } +} + +func TestFormatPolicyFragmentID(t *testing.T) { + actual := NewPolicyFragmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "policyFragmentValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/policyFragments/policyFragmentValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePolicyFragmentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PolicyFragmentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/policyFragments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/policyFragments/policyFragmentValue", + Expected: &PolicyFragmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + PolicyFragmentName: "policyFragmentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/policyFragments/policyFragmentValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePolicyFragmentID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.PolicyFragmentName != v.Expected.PolicyFragmentName { + t.Fatalf("Expected %q but got %q for PolicyFragmentName", v.Expected.PolicyFragmentName, actual.PolicyFragmentName) + } + + } +} + +func TestParsePolicyFragmentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PolicyFragmentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/policyFragments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pOlIcYfRaGmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/policyFragments/policyFragmentValue", + Expected: &PolicyFragmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + PolicyFragmentName: "policyFragmentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/policyFragments/policyFragmentValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pOlIcYfRaGmEnTs/pOlIcYfRaGmEnTvAlUe", + Expected: &PolicyFragmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + PolicyFragmentName: "pOlIcYfRaGmEnTvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pOlIcYfRaGmEnTs/pOlIcYfRaGmEnTvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePolicyFragmentIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.PolicyFragmentName != v.Expected.PolicyFragmentName { + t.Fatalf("Expected %q but got %q for PolicyFragmentName", v.Expected.PolicyFragmentName, actual.PolicyFragmentName) + } + + } +} + +func TestSegmentsForPolicyFragmentId(t *testing.T) { + segments := PolicyFragmentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PolicyFragmentId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/id_service.go b/resource-manager/apimanagement/2024-05-01/policyfragment/id_service.go new file mode 100644 index 00000000000..e0ab31ef120 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/id_service.go @@ -0,0 +1,130 @@ +package policyfragment + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/id_service_test.go b/resource-manager/apimanagement/2024-05-01/policyfragment/id_service_test.go new file mode 100644 index 00000000000..b19542febe9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/id_service_test.go @@ -0,0 +1,282 @@ +package policyfragment + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/id_workspace.go b/resource-manager/apimanagement/2024-05-01/policyfragment/id_workspace.go new file mode 100644 index 00000000000..334ecf5425c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/id_workspace.go @@ -0,0 +1,139 @@ +package policyfragment + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/id_workspace_test.go b/resource-manager/apimanagement/2024-05-01/policyfragment/id_workspace_test.go new file mode 100644 index 00000000000..84556fbddd5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/id_workspace_test.go @@ -0,0 +1,327 @@ +package policyfragment + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/id_workspacepolicyfragment.go b/resource-manager/apimanagement/2024-05-01/policyfragment/id_workspacepolicyfragment.go new file mode 100644 index 00000000000..eed247a5b17 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/id_workspacepolicyfragment.go @@ -0,0 +1,148 @@ +package policyfragment + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspacePolicyFragmentId{}) +} + +var _ resourceids.ResourceId = &WorkspacePolicyFragmentId{} + +// WorkspacePolicyFragmentId is a struct representing the Resource ID for a Workspace Policy Fragment +type WorkspacePolicyFragmentId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + PolicyFragmentName string +} + +// NewWorkspacePolicyFragmentID returns a new WorkspacePolicyFragmentId struct +func NewWorkspacePolicyFragmentID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, policyFragmentName string) WorkspacePolicyFragmentId { + return WorkspacePolicyFragmentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + PolicyFragmentName: policyFragmentName, + } +} + +// ParseWorkspacePolicyFragmentID parses 'input' into a WorkspacePolicyFragmentId +func ParseWorkspacePolicyFragmentID(input string) (*WorkspacePolicyFragmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspacePolicyFragmentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspacePolicyFragmentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspacePolicyFragmentIDInsensitively parses 'input' case-insensitively into a WorkspacePolicyFragmentId +// note: this method should only be used for API response data and not user input +func ParseWorkspacePolicyFragmentIDInsensitively(input string) (*WorkspacePolicyFragmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspacePolicyFragmentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspacePolicyFragmentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspacePolicyFragmentId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.PolicyFragmentName, ok = input.Parsed["policyFragmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "policyFragmentName", input) + } + + return nil +} + +// ValidateWorkspacePolicyFragmentID checks that 'input' can be parsed as a Workspace Policy Fragment ID +func ValidateWorkspacePolicyFragmentID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspacePolicyFragmentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Policy Fragment ID +func (id WorkspacePolicyFragmentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/policyFragments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.PolicyFragmentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Policy Fragment ID +func (id WorkspacePolicyFragmentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticPolicyFragments", "policyFragments", "policyFragments"), + resourceids.UserSpecifiedSegment("policyFragmentName", "policyFragmentValue"), + } +} + +// String returns a human-readable description of this Workspace Policy Fragment ID +func (id WorkspacePolicyFragmentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Policy Fragment Name: %q", id.PolicyFragmentName), + } + return fmt.Sprintf("Workspace Policy Fragment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/id_workspacepolicyfragment_test.go b/resource-manager/apimanagement/2024-05-01/policyfragment/id_workspacepolicyfragment_test.go new file mode 100644 index 00000000000..6b9e4f912c9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/id_workspacepolicyfragment_test.go @@ -0,0 +1,372 @@ +package policyfragment + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspacePolicyFragmentId{} + +func TestNewWorkspacePolicyFragmentID(t *testing.T) { + id := NewWorkspacePolicyFragmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "policyFragmentValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.PolicyFragmentName != "policyFragmentValue" { + t.Fatalf("Expected %q but got %q for Segment 'PolicyFragmentName'", id.PolicyFragmentName, "policyFragmentValue") + } +} + +func TestFormatWorkspacePolicyFragmentID(t *testing.T) { + actual := NewWorkspacePolicyFragmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "policyFragmentValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/policyFragments/policyFragmentValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspacePolicyFragmentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspacePolicyFragmentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/policyFragments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/policyFragments/policyFragmentValue", + Expected: &WorkspacePolicyFragmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + PolicyFragmentName: "policyFragmentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/policyFragments/policyFragmentValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspacePolicyFragmentID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.PolicyFragmentName != v.Expected.PolicyFragmentName { + t.Fatalf("Expected %q but got %q for PolicyFragmentName", v.Expected.PolicyFragmentName, actual.PolicyFragmentName) + } + + } +} + +func TestParseWorkspacePolicyFragmentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspacePolicyFragmentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/policyFragments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pOlIcYfRaGmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/policyFragments/policyFragmentValue", + Expected: &WorkspacePolicyFragmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + PolicyFragmentName: "policyFragmentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/policyFragments/policyFragmentValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pOlIcYfRaGmEnTs/pOlIcYfRaGmEnTvAlUe", + Expected: &WorkspacePolicyFragmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + PolicyFragmentName: "pOlIcYfRaGmEnTvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pOlIcYfRaGmEnTs/pOlIcYfRaGmEnTvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspacePolicyFragmentIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.PolicyFragmentName != v.Expected.PolicyFragmentName { + t.Fatalf("Expected %q but got %q for PolicyFragmentName", v.Expected.PolicyFragmentName, actual.PolicyFragmentName) + } + + } +} + +func TestSegmentsForWorkspacePolicyFragmentId(t *testing.T) { + segments := WorkspacePolicyFragmentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspacePolicyFragmentId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/policyfragment/method_createorupdate.go new file mode 100644 index 00000000000..926a279b604 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/method_createorupdate.go @@ -0,0 +1,103 @@ +package policyfragment + +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 *PolicyFragmentContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c PolicyFragmentClient) CreateOrUpdate(ctx context.Context, id PolicyFragmentId, input PolicyFragmentContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 PolicyFragmentClient) CreateOrUpdateThenPoll(ctx context.Context, id PolicyFragmentId, input PolicyFragmentContract, options CreateOrUpdateOperationOptions) error { + result, err := c.CreateOrUpdate(ctx, id, input, options) + 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/apimanagement/2024-05-01/policyfragment/method_delete.go b/resource-manager/apimanagement/2024-05-01/policyfragment/method_delete.go new file mode 100644 index 00000000000..8a0d95204ce --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/method_delete.go @@ -0,0 +1,76 @@ +package policyfragment + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c PolicyFragmentClient) Delete(ctx context.Context, id PolicyFragmentId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/method_get.go b/resource-manager/apimanagement/2024-05-01/policyfragment/method_get.go new file mode 100644 index 00000000000..3aa646fafdd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/method_get.go @@ -0,0 +1,83 @@ +package policyfragment + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyFragmentContract +} + +type GetOperationOptions struct { + Format *PolicyFragmentContentFormat +} + +func DefaultGetOperationOptions() GetOperationOptions { + return GetOperationOptions{} +} + +func (o GetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o GetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o GetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Format != nil { + out.Append("format", fmt.Sprintf("%v", *o.Format)) + } + return &out +} + +// Get ... +func (c PolicyFragmentClient) Get(ctx context.Context, id PolicyFragmentId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + 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 PolicyFragmentContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/policyfragment/method_getentitytag.go new file mode 100644 index 00000000000..1d3b811f0e0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/method_getentitytag.go @@ -0,0 +1,46 @@ +package policyfragment + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c PolicyFragmentClient) GetEntityTag(ctx context.Context, id PolicyFragmentId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/policyfragment/method_listbyservice.go new file mode 100644 index 00000000000..e9fcb07b896 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/method_listbyservice.go @@ -0,0 +1,145 @@ +package policyfragment + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PolicyFragmentContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []PolicyFragmentContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Orderby *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c PolicyFragmentClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/policyFragments", 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 *[]PolicyFragmentContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c PolicyFragmentClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, PolicyFragmentContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PolicyFragmentClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate PolicyFragmentContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]PolicyFragmentContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/method_listreferences.go b/resource-manager/apimanagement/2024-05-01/policyfragment/method_listreferences.go new file mode 100644 index 00000000000..37993c71c0d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/method_listreferences.go @@ -0,0 +1,137 @@ +package policyfragment + +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 ListReferencesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Resource +} + +type ListReferencesCompleteResult struct { + LatestHttpResponse *http.Response + Items []Resource +} + +type ListReferencesOperationOptions struct { + Skip *int64 + Top *int64 +} + +func DefaultListReferencesOperationOptions() ListReferencesOperationOptions { + return ListReferencesOperationOptions{} +} + +func (o ListReferencesOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListReferencesOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListReferencesOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListReferencesCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListReferencesCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListReferences ... +func (c PolicyFragmentClient) ListReferences(ctx context.Context, id PolicyFragmentId, options ListReferencesOperationOptions) (result ListReferencesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + OptionsObject: options, + Pager: &ListReferencesCustomPager{}, + Path: fmt.Sprintf("%s/listReferences", 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 *[]Resource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListReferencesComplete retrieves all the results into a single object +func (c PolicyFragmentClient) ListReferencesComplete(ctx context.Context, id PolicyFragmentId, options ListReferencesOperationOptions) (ListReferencesCompleteResult, error) { + return c.ListReferencesCompleteMatchingPredicate(ctx, id, options, ResourceOperationPredicate{}) +} + +// ListReferencesCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PolicyFragmentClient) ListReferencesCompleteMatchingPredicate(ctx context.Context, id PolicyFragmentId, options ListReferencesOperationOptions, predicate ResourceOperationPredicate) (result ListReferencesCompleteResult, err error) { + items := make([]Resource, 0) + + resp, err := c.ListReferences(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListReferencesCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentcreateorupdate.go b/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentcreateorupdate.go new file mode 100644 index 00000000000..07c7352e49d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentcreateorupdate.go @@ -0,0 +1,103 @@ +package policyfragment + +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 WorkspacePolicyFragmentCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *PolicyFragmentContract +} + +type WorkspacePolicyFragmentCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspacePolicyFragmentCreateOrUpdateOperationOptions() WorkspacePolicyFragmentCreateOrUpdateOperationOptions { + return WorkspacePolicyFragmentCreateOrUpdateOperationOptions{} +} + +func (o WorkspacePolicyFragmentCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspacePolicyFragmentCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspacePolicyFragmentCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspacePolicyFragmentCreateOrUpdate ... +func (c PolicyFragmentClient) WorkspacePolicyFragmentCreateOrUpdate(ctx context.Context, id WorkspacePolicyFragmentId, input PolicyFragmentContract, options WorkspacePolicyFragmentCreateOrUpdateOperationOptions) (result WorkspacePolicyFragmentCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 +} + +// WorkspacePolicyFragmentCreateOrUpdateThenPoll performs WorkspacePolicyFragmentCreateOrUpdate then polls until it's completed +func (c PolicyFragmentClient) WorkspacePolicyFragmentCreateOrUpdateThenPoll(ctx context.Context, id WorkspacePolicyFragmentId, input PolicyFragmentContract, options WorkspacePolicyFragmentCreateOrUpdateOperationOptions) error { + result, err := c.WorkspacePolicyFragmentCreateOrUpdate(ctx, id, input, options) + if err != nil { + return fmt.Errorf("performing WorkspacePolicyFragmentCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after WorkspacePolicyFragmentCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentdelete.go b/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentdelete.go new file mode 100644 index 00000000000..3c175e499a5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentdelete.go @@ -0,0 +1,76 @@ +package policyfragment + +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 WorkspacePolicyFragmentDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type WorkspacePolicyFragmentDeleteOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspacePolicyFragmentDeleteOperationOptions() WorkspacePolicyFragmentDeleteOperationOptions { + return WorkspacePolicyFragmentDeleteOperationOptions{} +} + +func (o WorkspacePolicyFragmentDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspacePolicyFragmentDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspacePolicyFragmentDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspacePolicyFragmentDelete ... +func (c PolicyFragmentClient) WorkspacePolicyFragmentDelete(ctx context.Context, id WorkspacePolicyFragmentId, options WorkspacePolicyFragmentDeleteOperationOptions) (result WorkspacePolicyFragmentDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentget.go b/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentget.go new file mode 100644 index 00000000000..24b3402ea1f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentget.go @@ -0,0 +1,83 @@ +package policyfragment + +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 WorkspacePolicyFragmentGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyFragmentContract +} + +type WorkspacePolicyFragmentGetOperationOptions struct { + Format *PolicyFragmentContentFormat +} + +func DefaultWorkspacePolicyFragmentGetOperationOptions() WorkspacePolicyFragmentGetOperationOptions { + return WorkspacePolicyFragmentGetOperationOptions{} +} + +func (o WorkspacePolicyFragmentGetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspacePolicyFragmentGetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspacePolicyFragmentGetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Format != nil { + out.Append("format", fmt.Sprintf("%v", *o.Format)) + } + return &out +} + +// WorkspacePolicyFragmentGet ... +func (c PolicyFragmentClient) WorkspacePolicyFragmentGet(ctx context.Context, id WorkspacePolicyFragmentId, options WorkspacePolicyFragmentGetOperationOptions) (result WorkspacePolicyFragmentGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + 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 PolicyFragmentContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentgetentitytag.go b/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentgetentitytag.go new file mode 100644 index 00000000000..c2c987854f8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentgetentitytag.go @@ -0,0 +1,46 @@ +package policyfragment + +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 WorkspacePolicyFragmentGetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspacePolicyFragmentGetEntityTag ... +func (c PolicyFragmentClient) WorkspacePolicyFragmentGetEntityTag(ctx context.Context, id WorkspacePolicyFragmentId) (result WorkspacePolicyFragmentGetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentlistbyservice.go b/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentlistbyservice.go new file mode 100644 index 00000000000..601c1855d17 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentlistbyservice.go @@ -0,0 +1,145 @@ +package policyfragment + +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 WorkspacePolicyFragmentListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PolicyFragmentContract +} + +type WorkspacePolicyFragmentListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []PolicyFragmentContract +} + +type WorkspacePolicyFragmentListByServiceOperationOptions struct { + Filter *string + Orderby *string + Skip *int64 + Top *int64 +} + +func DefaultWorkspacePolicyFragmentListByServiceOperationOptions() WorkspacePolicyFragmentListByServiceOperationOptions { + return WorkspacePolicyFragmentListByServiceOperationOptions{} +} + +func (o WorkspacePolicyFragmentListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspacePolicyFragmentListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspacePolicyFragmentListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspacePolicyFragmentListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspacePolicyFragmentListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspacePolicyFragmentListByService ... +func (c PolicyFragmentClient) WorkspacePolicyFragmentListByService(ctx context.Context, id WorkspaceId, options WorkspacePolicyFragmentListByServiceOperationOptions) (result WorkspacePolicyFragmentListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspacePolicyFragmentListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/policyFragments", 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 *[]PolicyFragmentContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspacePolicyFragmentListByServiceComplete retrieves all the results into a single object +func (c PolicyFragmentClient) WorkspacePolicyFragmentListByServiceComplete(ctx context.Context, id WorkspaceId, options WorkspacePolicyFragmentListByServiceOperationOptions) (WorkspacePolicyFragmentListByServiceCompleteResult, error) { + return c.WorkspacePolicyFragmentListByServiceCompleteMatchingPredicate(ctx, id, options, PolicyFragmentContractOperationPredicate{}) +} + +// WorkspacePolicyFragmentListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PolicyFragmentClient) WorkspacePolicyFragmentListByServiceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options WorkspacePolicyFragmentListByServiceOperationOptions, predicate PolicyFragmentContractOperationPredicate) (result WorkspacePolicyFragmentListByServiceCompleteResult, err error) { + items := make([]PolicyFragmentContract, 0) + + resp, err := c.WorkspacePolicyFragmentListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspacePolicyFragmentListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentlistreferences.go b/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentlistreferences.go new file mode 100644 index 00000000000..fca10ec83a6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentlistreferences.go @@ -0,0 +1,137 @@ +package policyfragment + +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 WorkspacePolicyFragmentListReferencesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Resource +} + +type WorkspacePolicyFragmentListReferencesCompleteResult struct { + LatestHttpResponse *http.Response + Items []Resource +} + +type WorkspacePolicyFragmentListReferencesOperationOptions struct { + Skip *int64 + Top *int64 +} + +func DefaultWorkspacePolicyFragmentListReferencesOperationOptions() WorkspacePolicyFragmentListReferencesOperationOptions { + return WorkspacePolicyFragmentListReferencesOperationOptions{} +} + +func (o WorkspacePolicyFragmentListReferencesOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspacePolicyFragmentListReferencesOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspacePolicyFragmentListReferencesOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspacePolicyFragmentListReferencesCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspacePolicyFragmentListReferencesCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspacePolicyFragmentListReferences ... +func (c PolicyFragmentClient) WorkspacePolicyFragmentListReferences(ctx context.Context, id WorkspacePolicyFragmentId, options WorkspacePolicyFragmentListReferencesOperationOptions) (result WorkspacePolicyFragmentListReferencesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + OptionsObject: options, + Pager: &WorkspacePolicyFragmentListReferencesCustomPager{}, + Path: fmt.Sprintf("%s/listReferences", 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 *[]Resource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspacePolicyFragmentListReferencesComplete retrieves all the results into a single object +func (c PolicyFragmentClient) WorkspacePolicyFragmentListReferencesComplete(ctx context.Context, id WorkspacePolicyFragmentId, options WorkspacePolicyFragmentListReferencesOperationOptions) (WorkspacePolicyFragmentListReferencesCompleteResult, error) { + return c.WorkspacePolicyFragmentListReferencesCompleteMatchingPredicate(ctx, id, options, ResourceOperationPredicate{}) +} + +// WorkspacePolicyFragmentListReferencesCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PolicyFragmentClient) WorkspacePolicyFragmentListReferencesCompleteMatchingPredicate(ctx context.Context, id WorkspacePolicyFragmentId, options WorkspacePolicyFragmentListReferencesOperationOptions, predicate ResourceOperationPredicate) (result WorkspacePolicyFragmentListReferencesCompleteResult, err error) { + items := make([]Resource, 0) + + resp, err := c.WorkspacePolicyFragmentListReferences(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspacePolicyFragmentListReferencesCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/model_policyfragmentcontract.go b/resource-manager/apimanagement/2024-05-01/policyfragment/model_policyfragmentcontract.go new file mode 100644 index 00000000000..d00e93210c7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/model_policyfragmentcontract.go @@ -0,0 +1,11 @@ +package policyfragment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyFragmentContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PolicyFragmentContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/model_policyfragmentcontractproperties.go b/resource-manager/apimanagement/2024-05-01/policyfragment/model_policyfragmentcontractproperties.go new file mode 100644 index 00000000000..eaf08d280b9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/model_policyfragmentcontractproperties.go @@ -0,0 +1,11 @@ +package policyfragment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyFragmentContractProperties struct { + Description *string `json:"description,omitempty"` + Format *PolicyFragmentContentFormat `json:"format,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + Value string `json:"value"` +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/model_resource.go b/resource-manager/apimanagement/2024-05-01/policyfragment/model_resource.go new file mode 100644 index 00000000000..d8c4cfe7c03 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/model_resource.go @@ -0,0 +1,10 @@ +package policyfragment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Resource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/policyfragment/predicates.go b/resource-manager/apimanagement/2024-05-01/policyfragment/predicates.go new file mode 100644 index 00000000000..2850f0aee3c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/predicates.go @@ -0,0 +1,50 @@ +package policyfragment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyFragmentContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PolicyFragmentContractOperationPredicate) Matches(input PolicyFragmentContract) 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 ResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ResourceOperationPredicate) Matches(input Resource) 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/apimanagement/2024-05-01/policyfragment/version.go b/resource-manager/apimanagement/2024-05-01/policyfragment/version.go new file mode 100644 index 00000000000..bfe42b7595b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyfragment/version.go @@ -0,0 +1,12 @@ +package policyfragment + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/policyfragment/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestriction/README.md b/resource-manager/apimanagement/2024-05-01/policyrestriction/README.md new file mode 100644 index 00000000000..74cb962fd75 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestriction/README.md @@ -0,0 +1,110 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyrestriction` Documentation + +The `policyrestriction` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyrestriction" +``` + + +### Client Initialization + +```go +client := policyrestriction.NewPolicyRestrictionClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PolicyRestrictionClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := policyrestriction.NewPolicyRestrictionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "policyRestrictionIdValue") + +payload := policyrestriction.PolicyRestrictionContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, policyrestriction.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PolicyRestrictionClient.Delete` + +```go +ctx := context.TODO() +id := policyrestriction.NewPolicyRestrictionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "policyRestrictionIdValue") + +read, err := client.Delete(ctx, id, policyrestriction.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PolicyRestrictionClient.Get` + +```go +ctx := context.TODO() +id := policyrestriction.NewPolicyRestrictionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "policyRestrictionIdValue") + +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: `PolicyRestrictionClient.GetEntityTag` + +```go +ctx := context.TODO() +id := policyrestriction.NewPolicyRestrictionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "policyRestrictionIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PolicyRestrictionClient.Update` + +```go +ctx := context.TODO() +id := policyrestriction.NewPolicyRestrictionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "policyRestrictionIdValue") + +payload := policyrestriction.PolicyRestrictionUpdateContract{ + // ... +} + + +read, err := client.Update(ctx, id, payload, policyrestriction.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/policyrestriction/client.go b/resource-manager/apimanagement/2024-05-01/policyrestriction/client.go new file mode 100644 index 00000000000..8f031b7e45a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestriction/client.go @@ -0,0 +1,26 @@ +package policyrestriction + +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 PolicyRestrictionClient struct { + Client *resourcemanager.Client +} + +func NewPolicyRestrictionClientWithBaseURI(sdkApi sdkEnv.Api) (*PolicyRestrictionClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "policyrestriction", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PolicyRestrictionClient: %+v", err) + } + + return &PolicyRestrictionClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestriction/constants.go b/resource-manager/apimanagement/2024-05-01/policyrestriction/constants.go new file mode 100644 index 00000000000..52b8aeec8f7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestriction/constants.go @@ -0,0 +1,51 @@ +package policyrestriction + +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 PolicyRestrictionRequireBase string + +const ( + PolicyRestrictionRequireBaseFalse PolicyRestrictionRequireBase = "false" + PolicyRestrictionRequireBaseTrue PolicyRestrictionRequireBase = "true" +) + +func PossibleValuesForPolicyRestrictionRequireBase() []string { + return []string{ + string(PolicyRestrictionRequireBaseFalse), + string(PolicyRestrictionRequireBaseTrue), + } +} + +func (s *PolicyRestrictionRequireBase) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePolicyRestrictionRequireBase(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePolicyRestrictionRequireBase(input string) (*PolicyRestrictionRequireBase, error) { + vals := map[string]PolicyRestrictionRequireBase{ + "false": PolicyRestrictionRequireBaseFalse, + "true": PolicyRestrictionRequireBaseTrue, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyRestrictionRequireBase(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestriction/id_policyrestriction.go b/resource-manager/apimanagement/2024-05-01/policyrestriction/id_policyrestriction.go new file mode 100644 index 00000000000..4791253dc53 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestriction/id_policyrestriction.go @@ -0,0 +1,139 @@ +package policyrestriction + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PolicyRestrictionId{}) +} + +var _ resourceids.ResourceId = &PolicyRestrictionId{} + +// PolicyRestrictionId is a struct representing the Resource ID for a Policy Restriction +type PolicyRestrictionId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + PolicyRestrictionId string +} + +// NewPolicyRestrictionID returns a new PolicyRestrictionId struct +func NewPolicyRestrictionID(subscriptionId string, resourceGroupName string, serviceName string, policyRestrictionId string) PolicyRestrictionId { + return PolicyRestrictionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + PolicyRestrictionId: policyRestrictionId, + } +} + +// ParsePolicyRestrictionID parses 'input' into a PolicyRestrictionId +func ParsePolicyRestrictionID(input string) (*PolicyRestrictionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PolicyRestrictionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PolicyRestrictionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePolicyRestrictionIDInsensitively parses 'input' case-insensitively into a PolicyRestrictionId +// note: this method should only be used for API response data and not user input +func ParsePolicyRestrictionIDInsensitively(input string) (*PolicyRestrictionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PolicyRestrictionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PolicyRestrictionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PolicyRestrictionId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.PolicyRestrictionId, ok = input.Parsed["policyRestrictionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "policyRestrictionId", input) + } + + return nil +} + +// ValidatePolicyRestrictionID checks that 'input' can be parsed as a Policy Restriction ID +func ValidatePolicyRestrictionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePolicyRestrictionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Policy Restriction ID +func (id PolicyRestrictionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/policyRestrictions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.PolicyRestrictionId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Policy Restriction ID +func (id PolicyRestrictionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticPolicyRestrictions", "policyRestrictions", "policyRestrictions"), + resourceids.UserSpecifiedSegment("policyRestrictionId", "policyRestrictionIdValue"), + } +} + +// String returns a human-readable description of this Policy Restriction ID +func (id PolicyRestrictionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Policy Restriction: %q", id.PolicyRestrictionId), + } + return fmt.Sprintf("Policy Restriction (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestriction/id_policyrestriction_test.go b/resource-manager/apimanagement/2024-05-01/policyrestriction/id_policyrestriction_test.go new file mode 100644 index 00000000000..ec8140b4430 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestriction/id_policyrestriction_test.go @@ -0,0 +1,327 @@ +package policyrestriction + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PolicyRestrictionId{} + +func TestNewPolicyRestrictionID(t *testing.T) { + id := NewPolicyRestrictionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "policyRestrictionIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.PolicyRestrictionId != "policyRestrictionIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'PolicyRestrictionId'", id.PolicyRestrictionId, "policyRestrictionIdValue") + } +} + +func TestFormatPolicyRestrictionID(t *testing.T) { + actual := NewPolicyRestrictionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "policyRestrictionIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/policyRestrictions/policyRestrictionIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePolicyRestrictionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PolicyRestrictionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/policyRestrictions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/policyRestrictions/policyRestrictionIdValue", + Expected: &PolicyRestrictionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + PolicyRestrictionId: "policyRestrictionIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/policyRestrictions/policyRestrictionIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePolicyRestrictionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.PolicyRestrictionId != v.Expected.PolicyRestrictionId { + t.Fatalf("Expected %q but got %q for PolicyRestrictionId", v.Expected.PolicyRestrictionId, actual.PolicyRestrictionId) + } + + } +} + +func TestParsePolicyRestrictionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PolicyRestrictionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/policyRestrictions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pOlIcYrEsTrIcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/policyRestrictions/policyRestrictionIdValue", + Expected: &PolicyRestrictionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + PolicyRestrictionId: "policyRestrictionIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/policyRestrictions/policyRestrictionIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pOlIcYrEsTrIcTiOnS/pOlIcYrEsTrIcTiOnIdVaLuE", + Expected: &PolicyRestrictionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + PolicyRestrictionId: "pOlIcYrEsTrIcTiOnIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pOlIcYrEsTrIcTiOnS/pOlIcYrEsTrIcTiOnIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePolicyRestrictionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.PolicyRestrictionId != v.Expected.PolicyRestrictionId { + t.Fatalf("Expected %q but got %q for PolicyRestrictionId", v.Expected.PolicyRestrictionId, actual.PolicyRestrictionId) + } + + } +} + +func TestSegmentsForPolicyRestrictionId(t *testing.T) { + segments := PolicyRestrictionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PolicyRestrictionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestriction/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/policyrestriction/method_createorupdate.go new file mode 100644 index 00000000000..56b8f26697a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestriction/method_createorupdate.go @@ -0,0 +1,88 @@ +package policyrestriction + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyRestrictionContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c PolicyRestrictionClient) CreateOrUpdate(ctx context.Context, id PolicyRestrictionId, input PolicyRestrictionContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 PolicyRestrictionContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestriction/method_delete.go b/resource-manager/apimanagement/2024-05-01/policyrestriction/method_delete.go new file mode 100644 index 00000000000..c4ec85cd65f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestriction/method_delete.go @@ -0,0 +1,76 @@ +package policyrestriction + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c PolicyRestrictionClient) Delete(ctx context.Context, id PolicyRestrictionId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestriction/method_get.go b/resource-manager/apimanagement/2024-05-01/policyrestriction/method_get.go new file mode 100644 index 00000000000..f6ed8b41e1c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestriction/method_get.go @@ -0,0 +1,54 @@ +package policyrestriction + +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 *PolicyRestrictionContract +} + +// Get ... +func (c PolicyRestrictionClient) Get(ctx context.Context, id PolicyRestrictionId) (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 PolicyRestrictionContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestriction/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/policyrestriction/method_getentitytag.go new file mode 100644 index 00000000000..a0b14f985bd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestriction/method_getentitytag.go @@ -0,0 +1,46 @@ +package policyrestriction + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c PolicyRestrictionClient) GetEntityTag(ctx context.Context, id PolicyRestrictionId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestriction/method_update.go b/resource-manager/apimanagement/2024-05-01/policyrestriction/method_update.go new file mode 100644 index 00000000000..87847cf947c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestriction/method_update.go @@ -0,0 +1,87 @@ +package policyrestriction + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyRestrictionContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c PolicyRestrictionClient) Update(ctx context.Context, id PolicyRestrictionId, input PolicyRestrictionUpdateContract, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 PolicyRestrictionContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestriction/model_policyrestrictioncontract.go b/resource-manager/apimanagement/2024-05-01/policyrestriction/model_policyrestrictioncontract.go new file mode 100644 index 00000000000..1cad5513ed8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestriction/model_policyrestrictioncontract.go @@ -0,0 +1,11 @@ +package policyrestriction + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyRestrictionContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PolicyRestrictionContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestriction/model_policyrestrictioncontractproperties.go b/resource-manager/apimanagement/2024-05-01/policyrestriction/model_policyrestrictioncontractproperties.go new file mode 100644 index 00000000000..4d88eb47ec3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestriction/model_policyrestrictioncontractproperties.go @@ -0,0 +1,9 @@ +package policyrestriction + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyRestrictionContractProperties struct { + RequireBase *PolicyRestrictionRequireBase `json:"requireBase,omitempty"` + Scope *string `json:"scope,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestriction/model_policyrestrictionupdatecontract.go b/resource-manager/apimanagement/2024-05-01/policyrestriction/model_policyrestrictionupdatecontract.go new file mode 100644 index 00000000000..494675742bb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestriction/model_policyrestrictionupdatecontract.go @@ -0,0 +1,8 @@ +package policyrestriction + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyRestrictionUpdateContract struct { + Properties *PolicyRestrictionContractProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestriction/version.go b/resource-manager/apimanagement/2024-05-01/policyrestriction/version.go new file mode 100644 index 00000000000..f716a879d34 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestriction/version.go @@ -0,0 +1,12 @@ +package policyrestriction + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/policyrestriction/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestrictions/README.md b/resource-manager/apimanagement/2024-05-01/policyrestrictions/README.md new file mode 100644 index 00000000000..e5d92e796b9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestrictions/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyrestrictions` Documentation + +The `policyrestrictions` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyrestrictions" +``` + + +### Client Initialization + +```go +client := policyrestrictions.NewPolicyRestrictionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PolicyRestrictionsClient.PolicyRestrictionListByService` + +```go +ctx := context.TODO() +id := policyrestrictions.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.PolicyRestrictionListByService(ctx, id)` can be used to do batched pagination +items, err := client.PolicyRestrictionListByServiceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/policyrestrictions/client.go b/resource-manager/apimanagement/2024-05-01/policyrestrictions/client.go new file mode 100644 index 00000000000..af23f982730 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestrictions/client.go @@ -0,0 +1,26 @@ +package policyrestrictions + +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 PolicyRestrictionsClient struct { + Client *resourcemanager.Client +} + +func NewPolicyRestrictionsClientWithBaseURI(sdkApi sdkEnv.Api) (*PolicyRestrictionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "policyrestrictions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PolicyRestrictionsClient: %+v", err) + } + + return &PolicyRestrictionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestrictions/constants.go b/resource-manager/apimanagement/2024-05-01/policyrestrictions/constants.go new file mode 100644 index 00000000000..68f6c1ed243 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestrictions/constants.go @@ -0,0 +1,51 @@ +package policyrestrictions + +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 PolicyRestrictionRequireBase string + +const ( + PolicyRestrictionRequireBaseFalse PolicyRestrictionRequireBase = "false" + PolicyRestrictionRequireBaseTrue PolicyRestrictionRequireBase = "true" +) + +func PossibleValuesForPolicyRestrictionRequireBase() []string { + return []string{ + string(PolicyRestrictionRequireBaseFalse), + string(PolicyRestrictionRequireBaseTrue), + } +} + +func (s *PolicyRestrictionRequireBase) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePolicyRestrictionRequireBase(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePolicyRestrictionRequireBase(input string) (*PolicyRestrictionRequireBase, error) { + vals := map[string]PolicyRestrictionRequireBase{ + "false": PolicyRestrictionRequireBaseFalse, + "true": PolicyRestrictionRequireBaseTrue, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyRestrictionRequireBase(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestrictions/id_service.go b/resource-manager/apimanagement/2024-05-01/policyrestrictions/id_service.go new file mode 100644 index 00000000000..cda4de7ca6c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestrictions/id_service.go @@ -0,0 +1,130 @@ +package policyrestrictions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestrictions/id_service_test.go b/resource-manager/apimanagement/2024-05-01/policyrestrictions/id_service_test.go new file mode 100644 index 00000000000..4255a1ff076 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestrictions/id_service_test.go @@ -0,0 +1,282 @@ +package policyrestrictions + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestrictions/method_policyrestrictionlistbyservice.go b/resource-manager/apimanagement/2024-05-01/policyrestrictions/method_policyrestrictionlistbyservice.go new file mode 100644 index 00000000000..b3fd33a3ca9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestrictions/method_policyrestrictionlistbyservice.go @@ -0,0 +1,105 @@ +package policyrestrictions + +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 PolicyRestrictionListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PolicyRestrictionContract +} + +type PolicyRestrictionListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []PolicyRestrictionContract +} + +type PolicyRestrictionListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *PolicyRestrictionListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// PolicyRestrictionListByService ... +func (c PolicyRestrictionsClient) PolicyRestrictionListByService(ctx context.Context, id ServiceId) (result PolicyRestrictionListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &PolicyRestrictionListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/policyRestrictions", 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 *[]PolicyRestrictionContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// PolicyRestrictionListByServiceComplete retrieves all the results into a single object +func (c PolicyRestrictionsClient) PolicyRestrictionListByServiceComplete(ctx context.Context, id ServiceId) (PolicyRestrictionListByServiceCompleteResult, error) { + return c.PolicyRestrictionListByServiceCompleteMatchingPredicate(ctx, id, PolicyRestrictionContractOperationPredicate{}) +} + +// PolicyRestrictionListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PolicyRestrictionsClient) PolicyRestrictionListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, predicate PolicyRestrictionContractOperationPredicate) (result PolicyRestrictionListByServiceCompleteResult, err error) { + items := make([]PolicyRestrictionContract, 0) + + resp, err := c.PolicyRestrictionListByService(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = PolicyRestrictionListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestrictions/model_policyrestrictioncontract.go b/resource-manager/apimanagement/2024-05-01/policyrestrictions/model_policyrestrictioncontract.go new file mode 100644 index 00000000000..2774541dcf5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestrictions/model_policyrestrictioncontract.go @@ -0,0 +1,11 @@ +package policyrestrictions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyRestrictionContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PolicyRestrictionContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestrictions/model_policyrestrictioncontractproperties.go b/resource-manager/apimanagement/2024-05-01/policyrestrictions/model_policyrestrictioncontractproperties.go new file mode 100644 index 00000000000..d5262844c6a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestrictions/model_policyrestrictioncontractproperties.go @@ -0,0 +1,9 @@ +package policyrestrictions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyRestrictionContractProperties struct { + RequireBase *PolicyRestrictionRequireBase `json:"requireBase,omitempty"` + Scope *string `json:"scope,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestrictions/predicates.go b/resource-manager/apimanagement/2024-05-01/policyrestrictions/predicates.go new file mode 100644 index 00000000000..2a9e2910907 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestrictions/predicates.go @@ -0,0 +1,27 @@ +package policyrestrictions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyRestrictionContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PolicyRestrictionContractOperationPredicate) Matches(input PolicyRestrictionContract) 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/apimanagement/2024-05-01/policyrestrictions/version.go b/resource-manager/apimanagement/2024-05-01/policyrestrictions/version.go new file mode 100644 index 00000000000..0d1a67a76b5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestrictions/version.go @@ -0,0 +1,12 @@ +package policyrestrictions + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/policyrestrictions/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/README.md b/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/README.md new file mode 100644 index 00000000000..993a034b6f5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/README.md @@ -0,0 +1,32 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations` Documentation + +The `policyrestrictionsvalidations` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations" +``` + + +### Client Initialization + +```go +client := policyrestrictionsvalidations.NewPolicyRestrictionsValidationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PolicyRestrictionsValidationsClient.PolicyRestrictionValidationsByService` + +```go +ctx := context.TODO() +id := policyrestrictionsvalidations.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +if err := client.PolicyRestrictionValidationsByServiceThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/client.go b/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/client.go new file mode 100644 index 00000000000..3d993a73d0c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/client.go @@ -0,0 +1,26 @@ +package policyrestrictionsvalidations + +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 PolicyRestrictionsValidationsClient struct { + Client *resourcemanager.Client +} + +func NewPolicyRestrictionsValidationsClientWithBaseURI(sdkApi sdkEnv.Api) (*PolicyRestrictionsValidationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "policyrestrictionsvalidations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PolicyRestrictionsValidationsClient: %+v", err) + } + + return &PolicyRestrictionsValidationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/constants.go b/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/constants.go new file mode 100644 index 00000000000..4d4a5368be8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/constants.go @@ -0,0 +1,57 @@ +package policyrestrictionsvalidations + +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 AsyncOperationStatus string + +const ( + AsyncOperationStatusFailed AsyncOperationStatus = "Failed" + AsyncOperationStatusInProgress AsyncOperationStatus = "InProgress" + AsyncOperationStatusStarted AsyncOperationStatus = "Started" + AsyncOperationStatusSucceeded AsyncOperationStatus = "Succeeded" +) + +func PossibleValuesForAsyncOperationStatus() []string { + return []string{ + string(AsyncOperationStatusFailed), + string(AsyncOperationStatusInProgress), + string(AsyncOperationStatusStarted), + string(AsyncOperationStatusSucceeded), + } +} + +func (s *AsyncOperationStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAsyncOperationStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAsyncOperationStatus(input string) (*AsyncOperationStatus, error) { + vals := map[string]AsyncOperationStatus{ + "failed": AsyncOperationStatusFailed, + "inprogress": AsyncOperationStatusInProgress, + "started": AsyncOperationStatusStarted, + "succeeded": AsyncOperationStatusSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AsyncOperationStatus(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/id_service.go b/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/id_service.go new file mode 100644 index 00000000000..815b858832d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/id_service.go @@ -0,0 +1,130 @@ +package policyrestrictionsvalidations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/id_service_test.go b/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/id_service_test.go new file mode 100644 index 00000000000..59c0f1c9d6f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/id_service_test.go @@ -0,0 +1,282 @@ +package policyrestrictionsvalidations + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/method_policyrestrictionvalidationsbyservice.go b/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/method_policyrestrictionvalidationsbyservice.go new file mode 100644 index 00000000000..c3a0de898ad --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/method_policyrestrictionvalidationsbyservice.go @@ -0,0 +1,71 @@ +package policyrestrictionsvalidations + +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 PolicyRestrictionValidationsByServiceOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *OperationResultContract +} + +// PolicyRestrictionValidationsByService ... +func (c PolicyRestrictionsValidationsClient) PolicyRestrictionValidationsByService(ctx context.Context, id ServiceId) (result PolicyRestrictionValidationsByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/validatePolicies", 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 +} + +// PolicyRestrictionValidationsByServiceThenPoll performs PolicyRestrictionValidationsByService then polls until it's completed +func (c PolicyRestrictionsValidationsClient) PolicyRestrictionValidationsByServiceThenPoll(ctx context.Context, id ServiceId) error { + result, err := c.PolicyRestrictionValidationsByService(ctx, id) + if err != nil { + return fmt.Errorf("performing PolicyRestrictionValidationsByService: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after PolicyRestrictionValidationsByService: %+v", err) + } + + return nil +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/model_errorfieldcontract.go b/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/model_errorfieldcontract.go new file mode 100644 index 00000000000..7db69397d10 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/model_errorfieldcontract.go @@ -0,0 +1,10 @@ +package policyrestrictionsvalidations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorFieldContract struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/model_errorresponsebody.go b/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/model_errorresponsebody.go new file mode 100644 index 00000000000..a8820d0b0e6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/model_errorresponsebody.go @@ -0,0 +1,10 @@ +package policyrestrictionsvalidations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorResponseBody struct { + Code *string `json:"code,omitempty"` + Details *[]ErrorFieldContract `json:"details,omitempty"` + Message *string `json:"message,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/model_operationresultcontract.go b/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/model_operationresultcontract.go new file mode 100644 index 00000000000..f52fd12c5df --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/model_operationresultcontract.go @@ -0,0 +1,11 @@ +package policyrestrictionsvalidations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationResultContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *OperationResultContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/model_operationresultcontractproperties.go b/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/model_operationresultcontractproperties.go new file mode 100644 index 00000000000..e8e8cf5d85c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/model_operationresultcontractproperties.go @@ -0,0 +1,44 @@ +package policyrestrictionsvalidations + +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 OperationResultContractProperties struct { + ActionLog *[]OperationResultLogItemContract `json:"actionLog,omitempty"` + Error *ErrorResponseBody `json:"error,omitempty"` + Id *string `json:"id,omitempty"` + ResultInfo *string `json:"resultInfo,omitempty"` + Started *string `json:"started,omitempty"` + Status *AsyncOperationStatus `json:"status,omitempty"` + Updated *string `json:"updated,omitempty"` +} + +func (o *OperationResultContractProperties) GetStartedAsTime() (*time.Time, error) { + if o.Started == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Started, "2006-01-02T15:04:05Z07:00") +} + +func (o *OperationResultContractProperties) SetStartedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Started = &formatted +} + +func (o *OperationResultContractProperties) GetUpdatedAsTime() (*time.Time, error) { + if o.Updated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Updated, "2006-01-02T15:04:05Z07:00") +} + +func (o *OperationResultContractProperties) SetUpdatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Updated = &formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/model_operationresultlogitemcontract.go b/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/model_operationresultlogitemcontract.go new file mode 100644 index 00000000000..ca41ab03ea3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/model_operationresultlogitemcontract.go @@ -0,0 +1,10 @@ +package policyrestrictionsvalidations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationResultLogItemContract struct { + Action *string `json:"action,omitempty"` + ObjectKey *string `json:"objectKey,omitempty"` + ObjectType *string `json:"objectType,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/version.go b/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/version.go new file mode 100644 index 00000000000..5844aba2ed8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/policyrestrictionsvalidations/version.go @@ -0,0 +1,12 @@ +package policyrestrictionsvalidations + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/policyrestrictionsvalidations/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/portalconfig/README.md b/resource-manager/apimanagement/2024-05-01/portalconfig/README.md new file mode 100644 index 00000000000..cf0dfea7544 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalconfig/README.md @@ -0,0 +1,111 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/portalconfig` Documentation + +The `portalconfig` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/portalconfig" +``` + + +### Client Initialization + +```go +client := portalconfig.NewPortalConfigClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PortalConfigClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := portalconfig.NewPortalConfigID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "portalConfigIdValue") + +payload := portalconfig.PortalConfigContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, portalconfig.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PortalConfigClient.Get` + +```go +ctx := context.TODO() +id := portalconfig.NewPortalConfigID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "portalConfigIdValue") + +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: `PortalConfigClient.GetEntityTag` + +```go +ctx := context.TODO() +id := portalconfig.NewPortalConfigID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "portalConfigIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PortalConfigClient.ListByService` + +```go +ctx := context.TODO() +id := portalconfig.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id)` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PortalConfigClient.Update` + +```go +ctx := context.TODO() +id := portalconfig.NewPortalConfigID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "portalConfigIdValue") + +payload := portalconfig.PortalConfigContract{ + // ... +} + + +read, err := client.Update(ctx, id, payload, portalconfig.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/portalconfig/client.go b/resource-manager/apimanagement/2024-05-01/portalconfig/client.go new file mode 100644 index 00000000000..5c58ba3ea50 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalconfig/client.go @@ -0,0 +1,26 @@ +package portalconfig + +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 PortalConfigClient struct { + Client *resourcemanager.Client +} + +func NewPortalConfigClientWithBaseURI(sdkApi sdkEnv.Api) (*PortalConfigClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "portalconfig", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PortalConfigClient: %+v", err) + } + + return &PortalConfigClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/portalconfig/constants.go b/resource-manager/apimanagement/2024-05-01/portalconfig/constants.go new file mode 100644 index 00000000000..5329a0b27fc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalconfig/constants.go @@ -0,0 +1,54 @@ +package portalconfig + +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 PortalSettingsCspMode string + +const ( + PortalSettingsCspModeDisabled PortalSettingsCspMode = "disabled" + PortalSettingsCspModeEnabled PortalSettingsCspMode = "enabled" + PortalSettingsCspModeReportOnly PortalSettingsCspMode = "reportOnly" +) + +func PossibleValuesForPortalSettingsCspMode() []string { + return []string{ + string(PortalSettingsCspModeDisabled), + string(PortalSettingsCspModeEnabled), + string(PortalSettingsCspModeReportOnly), + } +} + +func (s *PortalSettingsCspMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePortalSettingsCspMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePortalSettingsCspMode(input string) (*PortalSettingsCspMode, error) { + vals := map[string]PortalSettingsCspMode{ + "disabled": PortalSettingsCspModeDisabled, + "enabled": PortalSettingsCspModeEnabled, + "reportonly": PortalSettingsCspModeReportOnly, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PortalSettingsCspMode(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/portalconfig/id_portalconfig.go b/resource-manager/apimanagement/2024-05-01/portalconfig/id_portalconfig.go new file mode 100644 index 00000000000..4217e87e470 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalconfig/id_portalconfig.go @@ -0,0 +1,139 @@ +package portalconfig + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PortalConfigId{}) +} + +var _ resourceids.ResourceId = &PortalConfigId{} + +// PortalConfigId is a struct representing the Resource ID for a Portal Config +type PortalConfigId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + PortalConfigId string +} + +// NewPortalConfigID returns a new PortalConfigId struct +func NewPortalConfigID(subscriptionId string, resourceGroupName string, serviceName string, portalConfigId string) PortalConfigId { + return PortalConfigId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + PortalConfigId: portalConfigId, + } +} + +// ParsePortalConfigID parses 'input' into a PortalConfigId +func ParsePortalConfigID(input string) (*PortalConfigId, error) { + parser := resourceids.NewParserFromResourceIdType(&PortalConfigId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PortalConfigId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePortalConfigIDInsensitively parses 'input' case-insensitively into a PortalConfigId +// note: this method should only be used for API response data and not user input +func ParsePortalConfigIDInsensitively(input string) (*PortalConfigId, error) { + parser := resourceids.NewParserFromResourceIdType(&PortalConfigId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PortalConfigId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PortalConfigId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.PortalConfigId, ok = input.Parsed["portalConfigId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "portalConfigId", input) + } + + return nil +} + +// ValidatePortalConfigID checks that 'input' can be parsed as a Portal Config ID +func ValidatePortalConfigID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePortalConfigID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Portal Config ID +func (id PortalConfigId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/portalConfigs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.PortalConfigId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Portal Config ID +func (id PortalConfigId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticPortalConfigs", "portalConfigs", "portalConfigs"), + resourceids.UserSpecifiedSegment("portalConfigId", "portalConfigIdValue"), + } +} + +// String returns a human-readable description of this Portal Config ID +func (id PortalConfigId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Portal Config: %q", id.PortalConfigId), + } + return fmt.Sprintf("Portal Config (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/portalconfig/id_portalconfig_test.go b/resource-manager/apimanagement/2024-05-01/portalconfig/id_portalconfig_test.go new file mode 100644 index 00000000000..6d63917a407 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalconfig/id_portalconfig_test.go @@ -0,0 +1,327 @@ +package portalconfig + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PortalConfigId{} + +func TestNewPortalConfigID(t *testing.T) { + id := NewPortalConfigID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "portalConfigIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.PortalConfigId != "portalConfigIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'PortalConfigId'", id.PortalConfigId, "portalConfigIdValue") + } +} + +func TestFormatPortalConfigID(t *testing.T) { + actual := NewPortalConfigID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "portalConfigIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/portalConfigs/portalConfigIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePortalConfigID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PortalConfigId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/portalConfigs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/portalConfigs/portalConfigIdValue", + Expected: &PortalConfigId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + PortalConfigId: "portalConfigIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/portalConfigs/portalConfigIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePortalConfigID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.PortalConfigId != v.Expected.PortalConfigId { + t.Fatalf("Expected %q but got %q for PortalConfigId", v.Expected.PortalConfigId, actual.PortalConfigId) + } + + } +} + +func TestParsePortalConfigIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PortalConfigId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/portalConfigs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pOrTaLcOnFiGs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/portalConfigs/portalConfigIdValue", + Expected: &PortalConfigId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + PortalConfigId: "portalConfigIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/portalConfigs/portalConfigIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pOrTaLcOnFiGs/pOrTaLcOnFiGiDvAlUe", + Expected: &PortalConfigId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + PortalConfigId: "pOrTaLcOnFiGiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pOrTaLcOnFiGs/pOrTaLcOnFiGiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePortalConfigIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.PortalConfigId != v.Expected.PortalConfigId { + t.Fatalf("Expected %q but got %q for PortalConfigId", v.Expected.PortalConfigId, actual.PortalConfigId) + } + + } +} + +func TestSegmentsForPortalConfigId(t *testing.T) { + segments := PortalConfigId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PortalConfigId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/portalconfig/id_service.go b/resource-manager/apimanagement/2024-05-01/portalconfig/id_service.go new file mode 100644 index 00000000000..fe235ccce02 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalconfig/id_service.go @@ -0,0 +1,130 @@ +package portalconfig + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/portalconfig/id_service_test.go b/resource-manager/apimanagement/2024-05-01/portalconfig/id_service_test.go new file mode 100644 index 00000000000..fe7f3c7b1e7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalconfig/id_service_test.go @@ -0,0 +1,282 @@ +package portalconfig + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/portalconfig/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/portalconfig/method_createorupdate.go new file mode 100644 index 00000000000..94bdf726259 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalconfig/method_createorupdate.go @@ -0,0 +1,87 @@ +package portalconfig + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PortalConfigContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c PortalConfigClient) CreateOrUpdate(ctx context.Context, id PortalConfigId, input PortalConfigContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 PortalConfigContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/portalconfig/method_get.go b/resource-manager/apimanagement/2024-05-01/portalconfig/method_get.go new file mode 100644 index 00000000000..755476c6e67 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalconfig/method_get.go @@ -0,0 +1,54 @@ +package portalconfig + +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 *PortalConfigContract +} + +// Get ... +func (c PortalConfigClient) Get(ctx context.Context, id PortalConfigId) (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 PortalConfigContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/portalconfig/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/portalconfig/method_getentitytag.go new file mode 100644 index 00000000000..72fdc64bba5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalconfig/method_getentitytag.go @@ -0,0 +1,46 @@ +package portalconfig + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c PortalConfigClient) GetEntityTag(ctx context.Context, id PortalConfigId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/portalconfig/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/portalconfig/method_listbyservice.go new file mode 100644 index 00000000000..0a0e1705d39 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalconfig/method_listbyservice.go @@ -0,0 +1,105 @@ +package portalconfig + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PortalConfigContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []PortalConfigContract +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c PortalConfigClient) ListByService(ctx context.Context, id ServiceId) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/portalConfigs", 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 *[]PortalConfigContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c PortalConfigClient) ListByServiceComplete(ctx context.Context, id ServiceId) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, PortalConfigContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PortalConfigClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, predicate PortalConfigContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]PortalConfigContract, 0) + + resp, err := c.ListByService(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/portalconfig/method_update.go b/resource-manager/apimanagement/2024-05-01/portalconfig/method_update.go new file mode 100644 index 00000000000..fce54b73ff3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalconfig/method_update.go @@ -0,0 +1,87 @@ +package portalconfig + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PortalConfigContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c PortalConfigClient) Update(ctx context.Context, id PortalConfigId, input PortalConfigContract, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 PortalConfigContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/portalconfig/model_portalconfigcontract.go b/resource-manager/apimanagement/2024-05-01/portalconfig/model_portalconfigcontract.go new file mode 100644 index 00000000000..ca96fa2b012 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalconfig/model_portalconfigcontract.go @@ -0,0 +1,11 @@ +package portalconfig + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PortalConfigContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PortalConfigProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/portalconfig/model_portalconfigcorsproperties.go b/resource-manager/apimanagement/2024-05-01/portalconfig/model_portalconfigcorsproperties.go new file mode 100644 index 00000000000..b4eb96d697f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalconfig/model_portalconfigcorsproperties.go @@ -0,0 +1,8 @@ +package portalconfig + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PortalConfigCorsProperties struct { + AllowedOrigins *[]string `json:"allowedOrigins,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/portalconfig/model_portalconfigcspproperties.go b/resource-manager/apimanagement/2024-05-01/portalconfig/model_portalconfigcspproperties.go new file mode 100644 index 00000000000..4e192de74f4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalconfig/model_portalconfigcspproperties.go @@ -0,0 +1,10 @@ +package portalconfig + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PortalConfigCspProperties struct { + AllowedSources *[]string `json:"allowedSources,omitempty"` + Mode *PortalSettingsCspMode `json:"mode,omitempty"` + ReportUri *[]string `json:"reportUri,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/portalconfig/model_portalconfigdelegationproperties.go b/resource-manager/apimanagement/2024-05-01/portalconfig/model_portalconfigdelegationproperties.go new file mode 100644 index 00000000000..3d2fa8ed0b6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalconfig/model_portalconfigdelegationproperties.go @@ -0,0 +1,11 @@ +package portalconfig + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PortalConfigDelegationProperties struct { + DelegateRegistration *bool `json:"delegateRegistration,omitempty"` + DelegateSubscription *bool `json:"delegateSubscription,omitempty"` + DelegationUrl *string `json:"delegationUrl,omitempty"` + ValidationKey *string `json:"validationKey,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/portalconfig/model_portalconfigproperties.go b/resource-manager/apimanagement/2024-05-01/portalconfig/model_portalconfigproperties.go new file mode 100644 index 00000000000..727e92b3f8b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalconfig/model_portalconfigproperties.go @@ -0,0 +1,13 @@ +package portalconfig + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PortalConfigProperties struct { + Cors *PortalConfigCorsProperties `json:"cors,omitempty"` + Csp *PortalConfigCspProperties `json:"csp,omitempty"` + Delegation *PortalConfigDelegationProperties `json:"delegation,omitempty"` + EnableBasicAuth *bool `json:"enableBasicAuth,omitempty"` + Signin *PortalConfigPropertiesSignin `json:"signin,omitempty"` + Signup *PortalConfigPropertiesSignup `json:"signup,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/portalconfig/model_portalconfigpropertiessignin.go b/resource-manager/apimanagement/2024-05-01/portalconfig/model_portalconfigpropertiessignin.go new file mode 100644 index 00000000000..631be4dec38 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalconfig/model_portalconfigpropertiessignin.go @@ -0,0 +1,8 @@ +package portalconfig + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PortalConfigPropertiesSignin struct { + Require *bool `json:"require,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/portalconfig/model_portalconfigpropertiessignup.go b/resource-manager/apimanagement/2024-05-01/portalconfig/model_portalconfigpropertiessignup.go new file mode 100644 index 00000000000..13c55fbe03d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalconfig/model_portalconfigpropertiessignup.go @@ -0,0 +1,8 @@ +package portalconfig + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PortalConfigPropertiesSignup struct { + TermsOfService *PortalConfigTermsOfServiceProperties `json:"termsOfService,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/portalconfig/model_portalconfigtermsofserviceproperties.go b/resource-manager/apimanagement/2024-05-01/portalconfig/model_portalconfigtermsofserviceproperties.go new file mode 100644 index 00000000000..becf05aa45c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalconfig/model_portalconfigtermsofserviceproperties.go @@ -0,0 +1,9 @@ +package portalconfig + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PortalConfigTermsOfServiceProperties struct { + RequireConsent *bool `json:"requireConsent,omitempty"` + Text *string `json:"text,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/portalconfig/predicates.go b/resource-manager/apimanagement/2024-05-01/portalconfig/predicates.go new file mode 100644 index 00000000000..197188ae75f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalconfig/predicates.go @@ -0,0 +1,27 @@ +package portalconfig + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PortalConfigContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PortalConfigContractOperationPredicate) Matches(input PortalConfigContract) 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/apimanagement/2024-05-01/portalconfig/version.go b/resource-manager/apimanagement/2024-05-01/portalconfig/version.go new file mode 100644 index 00000000000..dc274f9d1ac --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalconfig/version.go @@ -0,0 +1,12 @@ +package portalconfig + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/portalconfig/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/portalrevision/README.md b/resource-manager/apimanagement/2024-05-01/portalrevision/README.md new file mode 100644 index 00000000000..7bb022eda3c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalrevision/README.md @@ -0,0 +1,103 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/portalrevision` Documentation + +The `portalrevision` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/portalrevision" +``` + + +### Client Initialization + +```go +client := portalrevision.NewPortalRevisionClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PortalRevisionClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := portalrevision.NewPortalRevisionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "portalRevisionIdValue") + +payload := portalrevision.PortalRevisionContract{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `PortalRevisionClient.Get` + +```go +ctx := context.TODO() +id := portalrevision.NewPortalRevisionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "portalRevisionIdValue") + +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: `PortalRevisionClient.GetEntityTag` + +```go +ctx := context.TODO() +id := portalrevision.NewPortalRevisionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "portalRevisionIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PortalRevisionClient.ListByService` + +```go +ctx := context.TODO() +id := portalrevision.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, portalrevision.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, portalrevision.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PortalRevisionClient.Update` + +```go +ctx := context.TODO() +id := portalrevision.NewPortalRevisionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "portalRevisionIdValue") + +payload := portalrevision.PortalRevisionContract{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload, portalrevision.DefaultUpdateOperationOptions()); err != nil { + // handle the error +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/portalrevision/client.go b/resource-manager/apimanagement/2024-05-01/portalrevision/client.go new file mode 100644 index 00000000000..4f2fa253331 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalrevision/client.go @@ -0,0 +1,26 @@ +package portalrevision + +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 PortalRevisionClient struct { + Client *resourcemanager.Client +} + +func NewPortalRevisionClientWithBaseURI(sdkApi sdkEnv.Api) (*PortalRevisionClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "portalrevision", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PortalRevisionClient: %+v", err) + } + + return &PortalRevisionClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/portalrevision/constants.go b/resource-manager/apimanagement/2024-05-01/portalrevision/constants.go new file mode 100644 index 00000000000..721b9d119dc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalrevision/constants.go @@ -0,0 +1,57 @@ +package portalrevision + +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 PortalRevisionStatus string + +const ( + PortalRevisionStatusCompleted PortalRevisionStatus = "completed" + PortalRevisionStatusFailed PortalRevisionStatus = "failed" + PortalRevisionStatusPending PortalRevisionStatus = "pending" + PortalRevisionStatusPublishing PortalRevisionStatus = "publishing" +) + +func PossibleValuesForPortalRevisionStatus() []string { + return []string{ + string(PortalRevisionStatusCompleted), + string(PortalRevisionStatusFailed), + string(PortalRevisionStatusPending), + string(PortalRevisionStatusPublishing), + } +} + +func (s *PortalRevisionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePortalRevisionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePortalRevisionStatus(input string) (*PortalRevisionStatus, error) { + vals := map[string]PortalRevisionStatus{ + "completed": PortalRevisionStatusCompleted, + "failed": PortalRevisionStatusFailed, + "pending": PortalRevisionStatusPending, + "publishing": PortalRevisionStatusPublishing, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PortalRevisionStatus(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/portalrevision/id_portalrevision.go b/resource-manager/apimanagement/2024-05-01/portalrevision/id_portalrevision.go new file mode 100644 index 00000000000..a4ef40e0335 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalrevision/id_portalrevision.go @@ -0,0 +1,139 @@ +package portalrevision + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PortalRevisionId{}) +} + +var _ resourceids.ResourceId = &PortalRevisionId{} + +// PortalRevisionId is a struct representing the Resource ID for a Portal Revision +type PortalRevisionId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + PortalRevisionId string +} + +// NewPortalRevisionID returns a new PortalRevisionId struct +func NewPortalRevisionID(subscriptionId string, resourceGroupName string, serviceName string, portalRevisionId string) PortalRevisionId { + return PortalRevisionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + PortalRevisionId: portalRevisionId, + } +} + +// ParsePortalRevisionID parses 'input' into a PortalRevisionId +func ParsePortalRevisionID(input string) (*PortalRevisionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PortalRevisionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PortalRevisionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePortalRevisionIDInsensitively parses 'input' case-insensitively into a PortalRevisionId +// note: this method should only be used for API response data and not user input +func ParsePortalRevisionIDInsensitively(input string) (*PortalRevisionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PortalRevisionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PortalRevisionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PortalRevisionId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.PortalRevisionId, ok = input.Parsed["portalRevisionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "portalRevisionId", input) + } + + return nil +} + +// ValidatePortalRevisionID checks that 'input' can be parsed as a Portal Revision ID +func ValidatePortalRevisionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePortalRevisionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Portal Revision ID +func (id PortalRevisionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/portalRevisions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.PortalRevisionId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Portal Revision ID +func (id PortalRevisionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticPortalRevisions", "portalRevisions", "portalRevisions"), + resourceids.UserSpecifiedSegment("portalRevisionId", "portalRevisionIdValue"), + } +} + +// String returns a human-readable description of this Portal Revision ID +func (id PortalRevisionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Portal Revision: %q", id.PortalRevisionId), + } + return fmt.Sprintf("Portal Revision (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/portalrevision/id_portalrevision_test.go b/resource-manager/apimanagement/2024-05-01/portalrevision/id_portalrevision_test.go new file mode 100644 index 00000000000..63af15d207e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalrevision/id_portalrevision_test.go @@ -0,0 +1,327 @@ +package portalrevision + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PortalRevisionId{} + +func TestNewPortalRevisionID(t *testing.T) { + id := NewPortalRevisionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "portalRevisionIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.PortalRevisionId != "portalRevisionIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'PortalRevisionId'", id.PortalRevisionId, "portalRevisionIdValue") + } +} + +func TestFormatPortalRevisionID(t *testing.T) { + actual := NewPortalRevisionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "portalRevisionIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/portalRevisions/portalRevisionIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePortalRevisionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PortalRevisionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/portalRevisions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/portalRevisions/portalRevisionIdValue", + Expected: &PortalRevisionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + PortalRevisionId: "portalRevisionIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/portalRevisions/portalRevisionIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePortalRevisionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.PortalRevisionId != v.Expected.PortalRevisionId { + t.Fatalf("Expected %q but got %q for PortalRevisionId", v.Expected.PortalRevisionId, actual.PortalRevisionId) + } + + } +} + +func TestParsePortalRevisionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PortalRevisionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/portalRevisions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pOrTaLrEvIsIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/portalRevisions/portalRevisionIdValue", + Expected: &PortalRevisionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + PortalRevisionId: "portalRevisionIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/portalRevisions/portalRevisionIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pOrTaLrEvIsIoNs/pOrTaLrEvIsIoNiDvAlUe", + Expected: &PortalRevisionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + PortalRevisionId: "pOrTaLrEvIsIoNiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pOrTaLrEvIsIoNs/pOrTaLrEvIsIoNiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePortalRevisionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.PortalRevisionId != v.Expected.PortalRevisionId { + t.Fatalf("Expected %q but got %q for PortalRevisionId", v.Expected.PortalRevisionId, actual.PortalRevisionId) + } + + } +} + +func TestSegmentsForPortalRevisionId(t *testing.T) { + segments := PortalRevisionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PortalRevisionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/portalrevision/id_service.go b/resource-manager/apimanagement/2024-05-01/portalrevision/id_service.go new file mode 100644 index 00000000000..6d27c56ea22 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalrevision/id_service.go @@ -0,0 +1,130 @@ +package portalrevision + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/portalrevision/id_service_test.go b/resource-manager/apimanagement/2024-05-01/portalrevision/id_service_test.go new file mode 100644 index 00000000000..86c652f3b2c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalrevision/id_service_test.go @@ -0,0 +1,282 @@ +package portalrevision + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/portalrevision/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/portalrevision/method_createorupdate.go new file mode 100644 index 00000000000..92cc04d2142 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalrevision/method_createorupdate.go @@ -0,0 +1,74 @@ +package portalrevision + +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 *PortalRevisionContract +} + +// CreateOrUpdate ... +func (c PortalRevisionClient) CreateOrUpdate(ctx context.Context, id PortalRevisionId, input PortalRevisionContract) (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 PortalRevisionClient) CreateOrUpdateThenPoll(ctx context.Context, id PortalRevisionId, input PortalRevisionContract) 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/apimanagement/2024-05-01/portalrevision/method_get.go b/resource-manager/apimanagement/2024-05-01/portalrevision/method_get.go new file mode 100644 index 00000000000..02c07947f35 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalrevision/method_get.go @@ -0,0 +1,54 @@ +package portalrevision + +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 *PortalRevisionContract +} + +// Get ... +func (c PortalRevisionClient) Get(ctx context.Context, id PortalRevisionId) (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 PortalRevisionContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/portalrevision/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/portalrevision/method_getentitytag.go new file mode 100644 index 00000000000..c29d462fb8e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalrevision/method_getentitytag.go @@ -0,0 +1,46 @@ +package portalrevision + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c PortalRevisionClient) GetEntityTag(ctx context.Context, id PortalRevisionId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/portalrevision/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/portalrevision/method_listbyservice.go new file mode 100644 index 00000000000..57df46678e2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalrevision/method_listbyservice.go @@ -0,0 +1,141 @@ +package portalrevision + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PortalRevisionContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []PortalRevisionContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c PortalRevisionClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/portalRevisions", 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 *[]PortalRevisionContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c PortalRevisionClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, PortalRevisionContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PortalRevisionClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate PortalRevisionContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]PortalRevisionContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/portalrevision/method_update.go b/resource-manager/apimanagement/2024-05-01/portalrevision/method_update.go new file mode 100644 index 00000000000..e3568960b04 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalrevision/method_update.go @@ -0,0 +1,103 @@ +package portalrevision + +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 *PortalRevisionContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c PortalRevisionClient) Update(ctx context.Context, id PortalRevisionId, input PortalRevisionContract, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 PortalRevisionClient) UpdateThenPoll(ctx context.Context, id PortalRevisionId, input PortalRevisionContract, options UpdateOperationOptions) error { + result, err := c.Update(ctx, id, input, options) + 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/apimanagement/2024-05-01/portalrevision/model_portalrevisioncontract.go b/resource-manager/apimanagement/2024-05-01/portalrevision/model_portalrevisioncontract.go new file mode 100644 index 00000000000..41f6a81e4a7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalrevision/model_portalrevisioncontract.go @@ -0,0 +1,11 @@ +package portalrevision + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PortalRevisionContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PortalRevisionContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/portalrevision/model_portalrevisioncontractproperties.go b/resource-manager/apimanagement/2024-05-01/portalrevision/model_portalrevisioncontractproperties.go new file mode 100644 index 00000000000..0776d03a413 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalrevision/model_portalrevisioncontractproperties.go @@ -0,0 +1,44 @@ +package portalrevision + +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 PortalRevisionContractProperties struct { + CreatedDateTime *string `json:"createdDateTime,omitempty"` + Description *string `json:"description,omitempty"` + IsCurrent *bool `json:"isCurrent,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + Status *PortalRevisionStatus `json:"status,omitempty"` + StatusDetails *string `json:"statusDetails,omitempty"` + UpdatedDateTime *string `json:"updatedDateTime,omitempty"` +} + +func (o *PortalRevisionContractProperties) GetCreatedDateTimeAsTime() (*time.Time, error) { + if o.CreatedDateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedDateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *PortalRevisionContractProperties) SetCreatedDateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedDateTime = &formatted +} + +func (o *PortalRevisionContractProperties) GetUpdatedDateTimeAsTime() (*time.Time, error) { + if o.UpdatedDateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.UpdatedDateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *PortalRevisionContractProperties) SetUpdatedDateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.UpdatedDateTime = &formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/portalrevision/predicates.go b/resource-manager/apimanagement/2024-05-01/portalrevision/predicates.go new file mode 100644 index 00000000000..fa276f0afc0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalrevision/predicates.go @@ -0,0 +1,27 @@ +package portalrevision + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PortalRevisionContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PortalRevisionContractOperationPredicate) Matches(input PortalRevisionContract) 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/apimanagement/2024-05-01/portalrevision/version.go b/resource-manager/apimanagement/2024-05-01/portalrevision/version.go new file mode 100644 index 00000000000..ed44e2c55d0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalrevision/version.go @@ -0,0 +1,12 @@ +package portalrevision + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/portalrevision/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/portalsettings/README.md b/resource-manager/apimanagement/2024-05-01/portalsettings/README.md new file mode 100644 index 00000000000..c68702db649 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalsettings/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/portalsettings` Documentation + +The `portalsettings` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/portalsettings" +``` + + +### Client Initialization + +```go +client := portalsettings.NewPortalSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PortalSettingsClient.ListByService` + +```go +ctx := context.TODO() +id := portalsettings.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +read, err := client.ListByService(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/apimanagement/2024-05-01/portalsettings/client.go b/resource-manager/apimanagement/2024-05-01/portalsettings/client.go new file mode 100644 index 00000000000..787e842a856 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalsettings/client.go @@ -0,0 +1,26 @@ +package portalsettings + +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 PortalSettingsClient struct { + Client *resourcemanager.Client +} + +func NewPortalSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*PortalSettingsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "portalsettings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PortalSettingsClient: %+v", err) + } + + return &PortalSettingsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/portalsettings/id_service.go b/resource-manager/apimanagement/2024-05-01/portalsettings/id_service.go new file mode 100644 index 00000000000..9c71fe38260 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalsettings/id_service.go @@ -0,0 +1,130 @@ +package portalsettings + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/portalsettings/id_service_test.go b/resource-manager/apimanagement/2024-05-01/portalsettings/id_service_test.go new file mode 100644 index 00000000000..5f47dcb30cd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalsettings/id_service_test.go @@ -0,0 +1,282 @@ +package portalsettings + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/portalsettings/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/portalsettings/method_listbyservice.go new file mode 100644 index 00000000000..0dc16a6d309 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalsettings/method_listbyservice.go @@ -0,0 +1,55 @@ +package portalsettings + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PortalSettingsCollection +} + +// ListByService ... +func (c PortalSettingsClient) ListByService(ctx context.Context, id ServiceId) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/portalsettings", 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 PortalSettingsCollection + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/portalsettings/model_portalsettingscollection.go b/resource-manager/apimanagement/2024-05-01/portalsettings/model_portalsettingscollection.go new file mode 100644 index 00000000000..fa2e062be83 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalsettings/model_portalsettingscollection.go @@ -0,0 +1,9 @@ +package portalsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PortalSettingsCollection struct { + Count *int64 `json:"count,omitempty"` + Value *[]PortalSettingsContract `json:"value,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/portalsettings/model_portalsettingscontract.go b/resource-manager/apimanagement/2024-05-01/portalsettings/model_portalsettingscontract.go new file mode 100644 index 00000000000..64695c0049b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalsettings/model_portalsettingscontract.go @@ -0,0 +1,11 @@ +package portalsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PortalSettingsContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PortalSettingsContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/portalsettings/model_portalsettingscontractproperties.go b/resource-manager/apimanagement/2024-05-01/portalsettings/model_portalsettingscontractproperties.go new file mode 100644 index 00000000000..8344707e90b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalsettings/model_portalsettingscontractproperties.go @@ -0,0 +1,13 @@ +package portalsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PortalSettingsContractProperties struct { + Enabled *bool `json:"enabled,omitempty"` + Subscriptions *SubscriptionsDelegationSettingsProperties `json:"subscriptions,omitempty"` + TermsOfService *TermsOfServiceProperties `json:"termsOfService,omitempty"` + Url *string `json:"url,omitempty"` + UserRegistration *RegistrationDelegationSettingsProperties `json:"userRegistration,omitempty"` + ValidationKey *string `json:"validationKey,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/portalsettings/model_registrationdelegationsettingsproperties.go b/resource-manager/apimanagement/2024-05-01/portalsettings/model_registrationdelegationsettingsproperties.go new file mode 100644 index 00000000000..2e67d2ba1d1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalsettings/model_registrationdelegationsettingsproperties.go @@ -0,0 +1,8 @@ +package portalsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegistrationDelegationSettingsProperties struct { + Enabled *bool `json:"enabled,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/portalsettings/model_subscriptionsdelegationsettingsproperties.go b/resource-manager/apimanagement/2024-05-01/portalsettings/model_subscriptionsdelegationsettingsproperties.go new file mode 100644 index 00000000000..9650b2a866f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalsettings/model_subscriptionsdelegationsettingsproperties.go @@ -0,0 +1,8 @@ +package portalsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionsDelegationSettingsProperties struct { + Enabled *bool `json:"enabled,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/portalsettings/model_termsofserviceproperties.go b/resource-manager/apimanagement/2024-05-01/portalsettings/model_termsofserviceproperties.go new file mode 100644 index 00000000000..b1457e3a424 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalsettings/model_termsofserviceproperties.go @@ -0,0 +1,10 @@ +package portalsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TermsOfServiceProperties struct { + ConsentRequired *bool `json:"consentRequired,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + Text *string `json:"text,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/portalsettings/version.go b/resource-manager/apimanagement/2024-05-01/portalsettings/version.go new file mode 100644 index 00000000000..19884676e9c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/portalsettings/version.go @@ -0,0 +1,12 @@ +package portalsettings + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/portalsettings/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/privateendpointconnections/README.md b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/README.md new file mode 100644 index 00000000000..886bf5d378d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/README.md @@ -0,0 +1,113 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/privateendpointconnections` Documentation + +The `privateendpointconnections` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/privateendpointconnections" +``` + + +### Client Initialization + +```go +client := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.PrivateEndpointConnectionCreateOrUpdate` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "privateEndpointConnectionValue") + +payload := privateendpointconnections.PrivateEndpointConnectionRequest{ + // ... +} + + +if err := client.PrivateEndpointConnectionCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.PrivateEndpointConnectionDelete` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "privateEndpointConnectionValue") + +if err := client.PrivateEndpointConnectionDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.PrivateEndpointConnectionGetByName` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "privateEndpointConnectionValue") + +read, err := client.PrivateEndpointConnectionGetByName(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.PrivateEndpointConnectionGetPrivateLinkResource` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "privateLinkResourceValue") + +read, err := client.PrivateEndpointConnectionGetPrivateLinkResource(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.PrivateEndpointConnectionListByService` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +read, err := client.PrivateEndpointConnectionListByService(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.PrivateEndpointConnectionListPrivateLinkResources` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +read, err := client.PrivateEndpointConnectionListPrivateLinkResources(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/apimanagement/2024-05-01/privateendpointconnections/client.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/client.go new file mode 100644 index 00000000000..3bf7a6afe1f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/client.go @@ -0,0 +1,26 @@ +package privateendpointconnections + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsClient struct { + Client *resourcemanager.Client +} + +func NewPrivateEndpointConnectionsClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateEndpointConnectionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "privateendpointconnections", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateEndpointConnectionsClient: %+v", err) + } + + return &PrivateEndpointConnectionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/privateendpointconnections/constants.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/constants.go new file mode 100644 index 00000000000..c5850609650 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/constants.go @@ -0,0 +1,101 @@ +package privateendpointconnections + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProvisioningState string + +const ( + PrivateEndpointConnectionProvisioningStateCreating PrivateEndpointConnectionProvisioningState = "Creating" + PrivateEndpointConnectionProvisioningStateDeleting PrivateEndpointConnectionProvisioningState = "Deleting" + PrivateEndpointConnectionProvisioningStateFailed PrivateEndpointConnectionProvisioningState = "Failed" + PrivateEndpointConnectionProvisioningStateSucceeded PrivateEndpointConnectionProvisioningState = "Succeeded" +) + +func PossibleValuesForPrivateEndpointConnectionProvisioningState() []string { + return []string{ + string(PrivateEndpointConnectionProvisioningStateCreating), + string(PrivateEndpointConnectionProvisioningStateDeleting), + string(PrivateEndpointConnectionProvisioningStateFailed), + string(PrivateEndpointConnectionProvisioningStateSucceeded), + } +} + +func (s *PrivateEndpointConnectionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointConnectionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointConnectionProvisioningState(input string) (*PrivateEndpointConnectionProvisioningState, error) { + vals := map[string]PrivateEndpointConnectionProvisioningState{ + "creating": PrivateEndpointConnectionProvisioningStateCreating, + "deleting": PrivateEndpointConnectionProvisioningStateDeleting, + "failed": PrivateEndpointConnectionProvisioningStateFailed, + "succeeded": PrivateEndpointConnectionProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointConnectionProvisioningState(input) + return &out, nil +} + +type PrivateEndpointServiceConnectionStatus string + +const ( + PrivateEndpointServiceConnectionStatusApproved PrivateEndpointServiceConnectionStatus = "Approved" + PrivateEndpointServiceConnectionStatusPending PrivateEndpointServiceConnectionStatus = "Pending" + PrivateEndpointServiceConnectionStatusRejected PrivateEndpointServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateEndpointServiceConnectionStatus() []string { + return []string{ + string(PrivateEndpointServiceConnectionStatusApproved), + string(PrivateEndpointServiceConnectionStatusPending), + string(PrivateEndpointServiceConnectionStatusRejected), + } +} + +func (s *PrivateEndpointServiceConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointServiceConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointServiceConnectionStatus(input string) (*PrivateEndpointServiceConnectionStatus, error) { + vals := map[string]PrivateEndpointServiceConnectionStatus{ + "approved": PrivateEndpointServiceConnectionStatusApproved, + "pending": PrivateEndpointServiceConnectionStatusPending, + "rejected": PrivateEndpointServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointServiceConnectionStatus(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/privateendpointconnections/id_privateendpointconnection.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/id_privateendpointconnection.go new file mode 100644 index 00000000000..6c2da784082 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/id_privateendpointconnection.go @@ -0,0 +1,139 @@ +package privateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PrivateEndpointConnectionId{}) +} + +var _ resourceids.ResourceId = &PrivateEndpointConnectionId{} + +// PrivateEndpointConnectionId is a struct representing the Resource ID for a Private Endpoint Connection +type PrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + PrivateEndpointConnectionName string +} + +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, serviceName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { + return PrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParsePrivateEndpointConnectionID parses 'input' into a PrivateEndpointConnectionId +func ParsePrivateEndpointConnectionID(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateEndpointConnectionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a PrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParsePrivateEndpointConnectionIDInsensitively(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateEndpointConnectionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateEndpointConnectionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.PrivateEndpointConnectionName, ok = input.Parsed["privateEndpointConnectionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateEndpointConnectionName", input) + } + + return nil +} + +// ValidatePrivateEndpointConnectionID checks that 'input' can be parsed as a Private Endpoint Connection ID +func ValidatePrivateEndpointConnectionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionValue"), + } +} + +// String returns a human-readable description of this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/privateendpointconnections/id_privateendpointconnection_test.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/id_privateendpointconnection_test.go new file mode 100644 index 00000000000..5437ef4f734 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/id_privateendpointconnection_test.go @@ -0,0 +1,327 @@ +package privateendpointconnections + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateEndpointConnectionId{} + +func TestNewPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "privateEndpointConnectionValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionValue") + } +} + +func TestFormatPrivateEndpointConnectionID(t *testing.T) { + actual := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "privateEndpointConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/privateEndpointConnections/privateEndpointConnectionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForPrivateEndpointConnectionId(t *testing.T) { + segments := PrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateEndpointConnectionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/privateendpointconnections/id_privatelinkresource.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/id_privatelinkresource.go new file mode 100644 index 00000000000..dfbab21cc34 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/id_privatelinkresource.go @@ -0,0 +1,139 @@ +package privateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PrivateLinkResourceId{}) +} + +var _ resourceids.ResourceId = &PrivateLinkResourceId{} + +// PrivateLinkResourceId is a struct representing the Resource ID for a Private Link Resource +type PrivateLinkResourceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + PrivateLinkResourceName string +} + +// NewPrivateLinkResourceID returns a new PrivateLinkResourceId struct +func NewPrivateLinkResourceID(subscriptionId string, resourceGroupName string, serviceName string, privateLinkResourceName string) PrivateLinkResourceId { + return PrivateLinkResourceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + PrivateLinkResourceName: privateLinkResourceName, + } +} + +// ParsePrivateLinkResourceID parses 'input' into a PrivateLinkResourceId +func ParsePrivateLinkResourceID(input string) (*PrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkResourceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkResourceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateLinkResourceIDInsensitively parses 'input' case-insensitively into a PrivateLinkResourceId +// note: this method should only be used for API response data and not user input +func ParsePrivateLinkResourceIDInsensitively(input string) (*PrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkResourceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkResourceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateLinkResourceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.PrivateLinkResourceName, ok = input.Parsed["privateLinkResourceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateLinkResourceName", input) + } + + return nil +} + +// ValidatePrivateLinkResourceID checks that 'input' can be parsed as a Private Link Resource ID +func ValidatePrivateLinkResourceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateLinkResourceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Link Resource ID +func (id PrivateLinkResourceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/privateLinkResources/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.PrivateLinkResourceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Link Resource ID +func (id PrivateLinkResourceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticPrivateLinkResources", "privateLinkResources", "privateLinkResources"), + resourceids.UserSpecifiedSegment("privateLinkResourceName", "privateLinkResourceValue"), + } +} + +// String returns a human-readable description of this Private Link Resource ID +func (id PrivateLinkResourceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Private Link Resource Name: %q", id.PrivateLinkResourceName), + } + return fmt.Sprintf("Private Link Resource (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/privateendpointconnections/id_privatelinkresource_test.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/id_privatelinkresource_test.go new file mode 100644 index 00000000000..0e0673a9538 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/id_privatelinkresource_test.go @@ -0,0 +1,327 @@ +package privateendpointconnections + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateLinkResourceId{} + +func TestNewPrivateLinkResourceID(t *testing.T) { + id := NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "privateLinkResourceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.PrivateLinkResourceName != "privateLinkResourceValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkResourceName'", id.PrivateLinkResourceName, "privateLinkResourceValue") + } +} + +func TestFormatPrivateLinkResourceID(t *testing.T) { + actual := NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "privateLinkResourceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/privateLinkResources/privateLinkResourceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateLinkResourceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkResourceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/privateLinkResources", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/privateLinkResources/privateLinkResourceValue", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + PrivateLinkResourceName: "privateLinkResourceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/privateLinkResources/privateLinkResourceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkResourceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.PrivateLinkResourceName != v.Expected.PrivateLinkResourceName { + t.Fatalf("Expected %q but got %q for PrivateLinkResourceName", v.Expected.PrivateLinkResourceName, actual.PrivateLinkResourceName) + } + + } +} + +func TestParsePrivateLinkResourceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkResourceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/privateLinkResources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRiVaTeLiNkReSoUrCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/privateLinkResources/privateLinkResourceValue", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + PrivateLinkResourceName: "privateLinkResourceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/privateLinkResources/privateLinkResourceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRiVaTeLiNkReSoUrCeS/pRiVaTeLiNkReSoUrCeVaLuE", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + PrivateLinkResourceName: "pRiVaTeLiNkReSoUrCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRiVaTeLiNkReSoUrCeS/pRiVaTeLiNkReSoUrCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkResourceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.PrivateLinkResourceName != v.Expected.PrivateLinkResourceName { + t.Fatalf("Expected %q but got %q for PrivateLinkResourceName", v.Expected.PrivateLinkResourceName, actual.PrivateLinkResourceName) + } + + } +} + +func TestSegmentsForPrivateLinkResourceId(t *testing.T) { + segments := PrivateLinkResourceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateLinkResourceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/privateendpointconnections/id_service.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/id_service.go new file mode 100644 index 00000000000..6954e3bf619 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/id_service.go @@ -0,0 +1,130 @@ +package privateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/privateendpointconnections/id_service_test.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/id_service_test.go new file mode 100644 index 00000000000..b78bda8b31e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/id_service_test.go @@ -0,0 +1,282 @@ +package privateendpointconnections + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/privateendpointconnections/method_privateendpointconnectioncreateorupdate.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/method_privateendpointconnectioncreateorupdate.go new file mode 100644 index 00000000000..f27cca4b283 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/method_privateendpointconnectioncreateorupdate.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 PrivateEndpointConnectionCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnection +} + +// PrivateEndpointConnectionCreateOrUpdate ... +func (c PrivateEndpointConnectionsClient) PrivateEndpointConnectionCreateOrUpdate(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnectionRequest) (result PrivateEndpointConnectionCreateOrUpdateOperationResponse, 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 +} + +// PrivateEndpointConnectionCreateOrUpdateThenPoll performs PrivateEndpointConnectionCreateOrUpdate then polls until it's completed +func (c PrivateEndpointConnectionsClient) PrivateEndpointConnectionCreateOrUpdateThenPoll(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnectionRequest) error { + result, err := c.PrivateEndpointConnectionCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing PrivateEndpointConnectionCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after PrivateEndpointConnectionCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/apimanagement/2024-05-01/privateendpointconnections/method_privateendpointconnectiondelete.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/method_privateendpointconnectiondelete.go new file mode 100644 index 00000000000..3dea5aca1b3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/method_privateendpointconnectiondelete.go @@ -0,0 +1,71 @@ +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 PrivateEndpointConnectionDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// PrivateEndpointConnectionDelete ... +func (c PrivateEndpointConnectionsClient) PrivateEndpointConnectionDelete(ctx context.Context, id PrivateEndpointConnectionId) (result PrivateEndpointConnectionDeleteOperationResponse, 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 +} + +// PrivateEndpointConnectionDeleteThenPoll performs PrivateEndpointConnectionDelete then polls until it's completed +func (c PrivateEndpointConnectionsClient) PrivateEndpointConnectionDeleteThenPoll(ctx context.Context, id PrivateEndpointConnectionId) error { + result, err := c.PrivateEndpointConnectionDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing PrivateEndpointConnectionDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after PrivateEndpointConnectionDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/apimanagement/2024-05-01/privateendpointconnections/method_privateendpointconnectiongetbyname.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/method_privateendpointconnectiongetbyname.go new file mode 100644 index 00000000000..79394dec05e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/method_privateendpointconnectiongetbyname.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 PrivateEndpointConnectionGetByNameOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnection +} + +// PrivateEndpointConnectionGetByName ... +func (c PrivateEndpointConnectionsClient) PrivateEndpointConnectionGetByName(ctx context.Context, id PrivateEndpointConnectionId) (result PrivateEndpointConnectionGetByNameOperationResponse, 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/apimanagement/2024-05-01/privateendpointconnections/method_privateendpointconnectiongetprivatelinkresource.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/method_privateendpointconnectiongetprivatelinkresource.go new file mode 100644 index 00000000000..44e1bf04851 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/method_privateendpointconnectiongetprivatelinkresource.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 PrivateEndpointConnectionGetPrivateLinkResourceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateLinkResource +} + +// PrivateEndpointConnectionGetPrivateLinkResource ... +func (c PrivateEndpointConnectionsClient) PrivateEndpointConnectionGetPrivateLinkResource(ctx context.Context, id PrivateLinkResourceId) (result PrivateEndpointConnectionGetPrivateLinkResourceOperationResponse, 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/apimanagement/2024-05-01/privateendpointconnections/method_privateendpointconnectionlistbyservice.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/method_privateendpointconnectionlistbyservice.go new file mode 100644 index 00000000000..6b9b574ef5f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/method_privateendpointconnectionlistbyservice.go @@ -0,0 +1,55 @@ +package privateendpointconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnectionListResult +} + +// PrivateEndpointConnectionListByService ... +func (c PrivateEndpointConnectionsClient) PrivateEndpointConnectionListByService(ctx context.Context, id ServiceId) (result PrivateEndpointConnectionListByServiceOperationResponse, 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()), + } + + 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 PrivateEndpointConnectionListResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/privateendpointconnections/method_privateendpointconnectionlistprivatelinkresources.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/method_privateendpointconnectionlistprivatelinkresources.go new file mode 100644 index 00000000000..e33993c077f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/method_privateendpointconnectionlistprivatelinkresources.go @@ -0,0 +1,55 @@ +package privateendpointconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionListPrivateLinkResourcesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateLinkResourceListResult +} + +// PrivateEndpointConnectionListPrivateLinkResources ... +func (c PrivateEndpointConnectionsClient) PrivateEndpointConnectionListPrivateLinkResources(ctx context.Context, id ServiceId) (result PrivateEndpointConnectionListPrivateLinkResourcesOperationResponse, 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()), + } + + 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 PrivateLinkResourceListResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privateendpoint.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privateendpoint.go new file mode 100644 index 00000000000..1bc8cf2a97c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privateendpoint.go @@ -0,0 +1,8 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privateendpointconnection.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privateendpointconnection.go new file mode 100644 index 00000000000..fde7f4db0fc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/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/apimanagement/2024-05-01/privateendpointconnections/model_privateendpointconnectionlistresult.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privateendpointconnectionlistresult.go new file mode 100644 index 00000000000..92a9ecb105a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privateendpointconnectionlistresult.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 PrivateEndpointConnectionListResult struct { + Value *[]PrivateEndpointConnection `json:"value,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privateendpointconnectionproperties.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..549d255f069 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privateendpointconnectionproperties.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 PrivateEndpointConnectionProperties struct { + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState"` + ProvisioningState *PrivateEndpointConnectionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privateendpointconnectionrequest.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privateendpointconnectionrequest.go new file mode 100644 index 00000000000..0feb07c1367 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privateendpointconnectionrequest.go @@ -0,0 +1,9 @@ +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 PrivateEndpointConnectionRequest struct { + Id *string `json:"id,omitempty"` + Properties *PrivateEndpointConnectionRequestProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privateendpointconnectionrequestproperties.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privateendpointconnectionrequestproperties.go new file mode 100644 index 00000000000..4eace3971c7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privateendpointconnectionrequestproperties.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 PrivateEndpointConnectionRequestProperties struct { + PrivateLinkServiceConnectionState *PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privatelinkresource.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privatelinkresource.go new file mode 100644 index 00000000000..039958494e3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privatelinkresource.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 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/apimanagement/2024-05-01/privateendpointconnections/model_privatelinkresourcelistresult.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privatelinkresourcelistresult.go new file mode 100644 index 00000000000..cc26a0f6985 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privatelinkresourcelistresult.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 PrivateLinkResourceListResult struct { + Value *[]PrivateLinkResource `json:"value,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privatelinkresourceproperties.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privatelinkresourceproperties.go new file mode 100644 index 00000000000..fa0261ca537 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privatelinkresourceproperties.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 PrivateLinkResourceProperties struct { + GroupId *string `json:"groupId,omitempty"` + RequiredMembers *[]string `json:"requiredMembers,omitempty"` + RequiredZoneNames *[]string `json:"requiredZoneNames,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..ec3f7a9f24c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateEndpointServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/privateendpointconnections/version.go b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/version.go new file mode 100644 index 00000000000..b541d16e87d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/privateendpointconnections/version.go @@ -0,0 +1,12 @@ +package privateendpointconnections + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/privateendpointconnections/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/product/README.md b/resource-manager/apimanagement/2024-05-01/product/README.md new file mode 100644 index 00000000000..83e74300dca --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/README.md @@ -0,0 +1,234 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/product` Documentation + +The `product` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/product" +``` + + +### Client Initialization + +```go +client := product.NewProductClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ProductClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := product.NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + +payload := product.ProductContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, product.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductClient.Delete` + +```go +ctx := context.TODO() +id := product.NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + +read, err := client.Delete(ctx, id, product.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductClient.Get` + +```go +ctx := context.TODO() +id := product.NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + +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: `ProductClient.GetEntityTag` + +```go +ctx := context.TODO() +id := product.NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductClient.ListByService` + +```go +ctx := context.TODO() +id := product.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, product.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, product.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ProductClient.Update` + +```go +ctx := context.TODO() +id := product.NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + +payload := product.ProductUpdateParameters{ + // ... +} + + +read, err := client.Update(ctx, id, payload, product.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductClient.WorkspaceProductCreateOrUpdate` + +```go +ctx := context.TODO() +id := product.NewWorkspaceProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue") + +payload := product.ProductContract{ + // ... +} + + +read, err := client.WorkspaceProductCreateOrUpdate(ctx, id, payload, product.DefaultWorkspaceProductCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductClient.WorkspaceProductDelete` + +```go +ctx := context.TODO() +id := product.NewWorkspaceProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue") + +read, err := client.WorkspaceProductDelete(ctx, id, product.DefaultWorkspaceProductDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductClient.WorkspaceProductGet` + +```go +ctx := context.TODO() +id := product.NewWorkspaceProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue") + +read, err := client.WorkspaceProductGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductClient.WorkspaceProductGetEntityTag` + +```go +ctx := context.TODO() +id := product.NewWorkspaceProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue") + +read, err := client.WorkspaceProductGetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductClient.WorkspaceProductListByService` + +```go +ctx := context.TODO() +id := product.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +// alternatively `client.WorkspaceProductListByService(ctx, id, product.DefaultWorkspaceProductListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.WorkspaceProductListByServiceComplete(ctx, id, product.DefaultWorkspaceProductListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ProductClient.WorkspaceProductUpdate` + +```go +ctx := context.TODO() +id := product.NewWorkspaceProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue") + +payload := product.ProductUpdateParameters{ + // ... +} + + +read, err := client.WorkspaceProductUpdate(ctx, id, payload, product.DefaultWorkspaceProductUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/product/client.go b/resource-manager/apimanagement/2024-05-01/product/client.go new file mode 100644 index 00000000000..20069da6c20 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/client.go @@ -0,0 +1,26 @@ +package product + +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 ProductClient struct { + Client *resourcemanager.Client +} + +func NewProductClientWithBaseURI(sdkApi sdkEnv.Api) (*ProductClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "product", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ProductClient: %+v", err) + } + + return &ProductClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/product/constants.go b/resource-manager/apimanagement/2024-05-01/product/constants.go new file mode 100644 index 00000000000..b1aa827fdb2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/constants.go @@ -0,0 +1,51 @@ +package product + +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 ProductState string + +const ( + ProductStateNotPublished ProductState = "notPublished" + ProductStatePublished ProductState = "published" +) + +func PossibleValuesForProductState() []string { + return []string{ + string(ProductStateNotPublished), + string(ProductStatePublished), + } +} + +func (s *ProductState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProductState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProductState(input string) (*ProductState, error) { + vals := map[string]ProductState{ + "notpublished": ProductStateNotPublished, + "published": ProductStatePublished, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProductState(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/product/id_product.go b/resource-manager/apimanagement/2024-05-01/product/id_product.go new file mode 100644 index 00000000000..95f18115dce --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/id_product.go @@ -0,0 +1,139 @@ +package product + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProductId{}) +} + +var _ resourceids.ResourceId = &ProductId{} + +// ProductId is a struct representing the Resource ID for a Product +type ProductId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ProductId string +} + +// NewProductID returns a new ProductId struct +func NewProductID(subscriptionId string, resourceGroupName string, serviceName string, productId string) ProductId { + return ProductId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ProductId: productId, + } +} + +// ParseProductID parses 'input' into a ProductId +func ParseProductID(input string) (*ProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProductIDInsensitively parses 'input' case-insensitively into a ProductId +// note: this method should only be used for API response data and not user input +func ParseProductIDInsensitively(input string) (*ProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProductId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ProductId, ok = input.Parsed["productId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "productId", input) + } + + return nil +} + +// ValidateProductID checks that 'input' can be parsed as a Product ID +func ValidateProductID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseProductID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Product ID +func (id ProductId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/products/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ProductId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Product ID +func (id ProductId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticProducts", "products", "products"), + resourceids.UserSpecifiedSegment("productId", "productIdValue"), + } +} + +// String returns a human-readable description of this Product ID +func (id ProductId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Product: %q", id.ProductId), + } + return fmt.Sprintf("Product (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/product/id_product_test.go b/resource-manager/apimanagement/2024-05-01/product/id_product_test.go new file mode 100644 index 00000000000..1653763dc9c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/id_product_test.go @@ -0,0 +1,327 @@ +package product + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ProductId{} + +func TestNewProductID(t *testing.T) { + id := NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ProductId != "productIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProductId'", id.ProductId, "productIdValue") + } +} + +func TestFormatProductID(t *testing.T) { + actual := NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProductID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestParseProductIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ProductId: "pRoDuCtIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestSegmentsForProductId(t *testing.T) { + segments := ProductId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProductId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/product/id_service.go b/resource-manager/apimanagement/2024-05-01/product/id_service.go new file mode 100644 index 00000000000..bb0983ca2df --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/id_service.go @@ -0,0 +1,130 @@ +package product + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/product/id_service_test.go b/resource-manager/apimanagement/2024-05-01/product/id_service_test.go new file mode 100644 index 00000000000..f4d780b0dbe --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/id_service_test.go @@ -0,0 +1,282 @@ +package product + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/product/id_workspace.go b/resource-manager/apimanagement/2024-05-01/product/id_workspace.go new file mode 100644 index 00000000000..72e09a3fc43 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/id_workspace.go @@ -0,0 +1,139 @@ +package product + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/product/id_workspace_test.go b/resource-manager/apimanagement/2024-05-01/product/id_workspace_test.go new file mode 100644 index 00000000000..c435920058d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/id_workspace_test.go @@ -0,0 +1,327 @@ +package product + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/product/id_workspaceproduct.go b/resource-manager/apimanagement/2024-05-01/product/id_workspaceproduct.go new file mode 100644 index 00000000000..6b11719ded0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/id_workspaceproduct.go @@ -0,0 +1,148 @@ +package product + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceProductId{}) +} + +var _ resourceids.ResourceId = &WorkspaceProductId{} + +// WorkspaceProductId is a struct representing the Resource ID for a Workspace Product +type WorkspaceProductId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + ProductId string +} + +// NewWorkspaceProductID returns a new WorkspaceProductId struct +func NewWorkspaceProductID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, productId string) WorkspaceProductId { + return WorkspaceProductId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + ProductId: productId, + } +} + +// ParseWorkspaceProductID parses 'input' into a WorkspaceProductId +func ParseWorkspaceProductID(input string) (*WorkspaceProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceProductId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceProductIDInsensitively parses 'input' case-insensitively into a WorkspaceProductId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceProductIDInsensitively(input string) (*WorkspaceProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceProductId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceProductId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.ProductId, ok = input.Parsed["productId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "productId", input) + } + + return nil +} + +// ValidateWorkspaceProductID checks that 'input' can be parsed as a Workspace Product ID +func ValidateWorkspaceProductID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceProductID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Product ID +func (id WorkspaceProductId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/products/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.ProductId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Product ID +func (id WorkspaceProductId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticProducts", "products", "products"), + resourceids.UserSpecifiedSegment("productId", "productIdValue"), + } +} + +// String returns a human-readable description of this Workspace Product ID +func (id WorkspaceProductId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Product: %q", id.ProductId), + } + return fmt.Sprintf("Workspace Product (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/product/id_workspaceproduct_test.go b/resource-manager/apimanagement/2024-05-01/product/id_workspaceproduct_test.go new file mode 100644 index 00000000000..2234134caf3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/id_workspaceproduct_test.go @@ -0,0 +1,372 @@ +package product + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceProductId{} + +func TestNewWorkspaceProductID(t *testing.T) { + id := NewWorkspaceProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.ProductId != "productIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProductId'", id.ProductId, "productIdValue") + } +} + +func TestFormatWorkspaceProductID(t *testing.T) { + actual := NewWorkspaceProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceProductID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue", + Expected: &WorkspaceProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceProductID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestParseWorkspaceProductIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pRoDuCtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue", + Expected: &WorkspaceProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pRoDuCtS/pRoDuCtIdVaLuE", + Expected: &WorkspaceProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + ProductId: "pRoDuCtIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceProductIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestSegmentsForWorkspaceProductId(t *testing.T) { + segments := WorkspaceProductId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceProductId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/product/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/product/method_createorupdate.go new file mode 100644 index 00000000000..2baf83fb505 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/method_createorupdate.go @@ -0,0 +1,88 @@ +package product + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ProductContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c ProductClient) CreateOrUpdate(ctx context.Context, id ProductId, input ProductContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 ProductContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/product/method_delete.go b/resource-manager/apimanagement/2024-05-01/product/method_delete.go new file mode 100644 index 00000000000..afc7d184b70 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/method_delete.go @@ -0,0 +1,79 @@ +package product + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + DeleteSubscriptions *bool + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.DeleteSubscriptions != nil { + out.Append("deleteSubscriptions", fmt.Sprintf("%v", *o.DeleteSubscriptions)) + } + return &out +} + +// Delete ... +func (c ProductClient) Delete(ctx context.Context, id ProductId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/product/method_get.go b/resource-manager/apimanagement/2024-05-01/product/method_get.go new file mode 100644 index 00000000000..b343c0f286c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/method_get.go @@ -0,0 +1,54 @@ +package product + +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 *ProductContract +} + +// Get ... +func (c ProductClient) Get(ctx context.Context, id ProductId) (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 ProductContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/product/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/product/method_getentitytag.go new file mode 100644 index 00000000000..667f4afad59 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/method_getentitytag.go @@ -0,0 +1,46 @@ +package product + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c ProductClient) GetEntityTag(ctx context.Context, id ProductId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/product/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/product/method_listbyservice.go new file mode 100644 index 00000000000..b1f50c8e42d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/method_listbyservice.go @@ -0,0 +1,149 @@ +package product + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ProductContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ProductContract +} + +type ListByServiceOperationOptions struct { + ExpandGroups *bool + Filter *string + Skip *int64 + Tags *string + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.ExpandGroups != nil { + out.Append("expandGroups", fmt.Sprintf("%v", *o.ExpandGroups)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Tags != nil { + out.Append("tags", fmt.Sprintf("%v", *o.Tags)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c ProductClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/products", 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 *[]ProductContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c ProductClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, ProductContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProductClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate ProductContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]ProductContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/product/method_update.go b/resource-manager/apimanagement/2024-05-01/product/method_update.go new file mode 100644 index 00000000000..fc36ecd5353 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/method_update.go @@ -0,0 +1,87 @@ +package product + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ProductContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c ProductClient) Update(ctx context.Context, id ProductId, input ProductUpdateParameters, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 ProductContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/product/method_workspaceproductcreateorupdate.go b/resource-manager/apimanagement/2024-05-01/product/method_workspaceproductcreateorupdate.go new file mode 100644 index 00000000000..af10ed64d9c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/method_workspaceproductcreateorupdate.go @@ -0,0 +1,88 @@ +package product + +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 WorkspaceProductCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ProductContract +} + +type WorkspaceProductCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceProductCreateOrUpdateOperationOptions() WorkspaceProductCreateOrUpdateOperationOptions { + return WorkspaceProductCreateOrUpdateOperationOptions{} +} + +func (o WorkspaceProductCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceProductCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceProductCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceProductCreateOrUpdate ... +func (c ProductClient) WorkspaceProductCreateOrUpdate(ctx context.Context, id WorkspaceProductId, input ProductContract, options WorkspaceProductCreateOrUpdateOperationOptions) (result WorkspaceProductCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 ProductContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/product/method_workspaceproductdelete.go b/resource-manager/apimanagement/2024-05-01/product/method_workspaceproductdelete.go new file mode 100644 index 00000000000..3bf8f536240 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/method_workspaceproductdelete.go @@ -0,0 +1,79 @@ +package product + +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 WorkspaceProductDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type WorkspaceProductDeleteOperationOptions struct { + DeleteSubscriptions *bool + IfMatch *string +} + +func DefaultWorkspaceProductDeleteOperationOptions() WorkspaceProductDeleteOperationOptions { + return WorkspaceProductDeleteOperationOptions{} +} + +func (o WorkspaceProductDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceProductDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceProductDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.DeleteSubscriptions != nil { + out.Append("deleteSubscriptions", fmt.Sprintf("%v", *o.DeleteSubscriptions)) + } + return &out +} + +// WorkspaceProductDelete ... +func (c ProductClient) WorkspaceProductDelete(ctx context.Context, id WorkspaceProductId, options WorkspaceProductDeleteOperationOptions) (result WorkspaceProductDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/product/method_workspaceproductget.go b/resource-manager/apimanagement/2024-05-01/product/method_workspaceproductget.go new file mode 100644 index 00000000000..d746f01c02e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/method_workspaceproductget.go @@ -0,0 +1,54 @@ +package product + +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 WorkspaceProductGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ProductContract +} + +// WorkspaceProductGet ... +func (c ProductClient) WorkspaceProductGet(ctx context.Context, id WorkspaceProductId) (result WorkspaceProductGetOperationResponse, 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 ProductContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/product/method_workspaceproductgetentitytag.go b/resource-manager/apimanagement/2024-05-01/product/method_workspaceproductgetentitytag.go new file mode 100644 index 00000000000..0cb17f542c7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/method_workspaceproductgetentitytag.go @@ -0,0 +1,46 @@ +package product + +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 WorkspaceProductGetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceProductGetEntityTag ... +func (c ProductClient) WorkspaceProductGetEntityTag(ctx context.Context, id WorkspaceProductId) (result WorkspaceProductGetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/product/method_workspaceproductlistbyservice.go b/resource-manager/apimanagement/2024-05-01/product/method_workspaceproductlistbyservice.go new file mode 100644 index 00000000000..457b9a161c9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/method_workspaceproductlistbyservice.go @@ -0,0 +1,149 @@ +package product + +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 WorkspaceProductListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ProductContract +} + +type WorkspaceProductListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ProductContract +} + +type WorkspaceProductListByServiceOperationOptions struct { + ExpandGroups *bool + Filter *string + Skip *int64 + Tags *string + Top *int64 +} + +func DefaultWorkspaceProductListByServiceOperationOptions() WorkspaceProductListByServiceOperationOptions { + return WorkspaceProductListByServiceOperationOptions{} +} + +func (o WorkspaceProductListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceProductListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceProductListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.ExpandGroups != nil { + out.Append("expandGroups", fmt.Sprintf("%v", *o.ExpandGroups)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Tags != nil { + out.Append("tags", fmt.Sprintf("%v", *o.Tags)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspaceProductListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceProductListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceProductListByService ... +func (c ProductClient) WorkspaceProductListByService(ctx context.Context, id WorkspaceId, options WorkspaceProductListByServiceOperationOptions) (result WorkspaceProductListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspaceProductListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/products", 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 *[]ProductContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceProductListByServiceComplete retrieves all the results into a single object +func (c ProductClient) WorkspaceProductListByServiceComplete(ctx context.Context, id WorkspaceId, options WorkspaceProductListByServiceOperationOptions) (WorkspaceProductListByServiceCompleteResult, error) { + return c.WorkspaceProductListByServiceCompleteMatchingPredicate(ctx, id, options, ProductContractOperationPredicate{}) +} + +// WorkspaceProductListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProductClient) WorkspaceProductListByServiceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options WorkspaceProductListByServiceOperationOptions, predicate ProductContractOperationPredicate) (result WorkspaceProductListByServiceCompleteResult, err error) { + items := make([]ProductContract, 0) + + resp, err := c.WorkspaceProductListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceProductListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/product/method_workspaceproductupdate.go b/resource-manager/apimanagement/2024-05-01/product/method_workspaceproductupdate.go new file mode 100644 index 00000000000..e1305ecd777 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/method_workspaceproductupdate.go @@ -0,0 +1,87 @@ +package product + +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 WorkspaceProductUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ProductContract +} + +type WorkspaceProductUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceProductUpdateOperationOptions() WorkspaceProductUpdateOperationOptions { + return WorkspaceProductUpdateOperationOptions{} +} + +func (o WorkspaceProductUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceProductUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceProductUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceProductUpdate ... +func (c ProductClient) WorkspaceProductUpdate(ctx context.Context, id WorkspaceProductId, input ProductUpdateParameters, options WorkspaceProductUpdateOperationOptions) (result WorkspaceProductUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 ProductContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/product/model_productcontract.go b/resource-manager/apimanagement/2024-05-01/product/model_productcontract.go new file mode 100644 index 00000000000..1d9178e386f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/model_productcontract.go @@ -0,0 +1,11 @@ +package product + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ProductContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/product/model_productcontractproperties.go b/resource-manager/apimanagement/2024-05-01/product/model_productcontractproperties.go new file mode 100644 index 00000000000..2ea12125c8b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/model_productcontractproperties.go @@ -0,0 +1,14 @@ +package product + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductContractProperties struct { + ApprovalRequired *bool `json:"approvalRequired,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName string `json:"displayName"` + State *ProductState `json:"state,omitempty"` + SubscriptionRequired *bool `json:"subscriptionRequired,omitempty"` + SubscriptionsLimit *int64 `json:"subscriptionsLimit,omitempty"` + Terms *string `json:"terms,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/product/model_productupdateparameters.go b/resource-manager/apimanagement/2024-05-01/product/model_productupdateparameters.go new file mode 100644 index 00000000000..d2d10c73851 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/model_productupdateparameters.go @@ -0,0 +1,8 @@ +package product + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductUpdateParameters struct { + Properties *ProductUpdateProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/product/model_productupdateproperties.go b/resource-manager/apimanagement/2024-05-01/product/model_productupdateproperties.go new file mode 100644 index 00000000000..ba683a371cc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/model_productupdateproperties.go @@ -0,0 +1,14 @@ +package product + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductUpdateProperties struct { + ApprovalRequired *bool `json:"approvalRequired,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + State *ProductState `json:"state,omitempty"` + SubscriptionRequired *bool `json:"subscriptionRequired,omitempty"` + SubscriptionsLimit *int64 `json:"subscriptionsLimit,omitempty"` + Terms *string `json:"terms,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/product/predicates.go b/resource-manager/apimanagement/2024-05-01/product/predicates.go new file mode 100644 index 00000000000..7e24e47c6fc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/predicates.go @@ -0,0 +1,27 @@ +package product + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ProductContractOperationPredicate) Matches(input ProductContract) 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/apimanagement/2024-05-01/product/version.go b/resource-manager/apimanagement/2024-05-01/product/version.go new file mode 100644 index 00000000000..b1534b4184b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/product/version.go @@ -0,0 +1,12 @@ +package product + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/product/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/productapi/README.md b/resource-manager/apimanagement/2024-05-01/productapi/README.md new file mode 100644 index 00000000000..f89de279c09 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapi/README.md @@ -0,0 +1,85 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/productapi` Documentation + +The `productapi` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/productapi" +``` + + +### Client Initialization + +```go +client := productapi.NewProductApiClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ProductApiClient.CheckEntityExists` + +```go +ctx := context.TODO() +id := productapi.NewProductApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "apiIdValue") + +read, err := client.CheckEntityExists(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductApiClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := productapi.NewProductApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "apiIdValue") + +read, err := client.CreateOrUpdate(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductApiClient.Delete` + +```go +ctx := context.TODO() +id := productapi.NewProductApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "apiIdValue") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductApiClient.ListByProduct` + +```go +ctx := context.TODO() +id := productapi.NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + +// alternatively `client.ListByProduct(ctx, id, productapi.DefaultListByProductOperationOptions())` can be used to do batched pagination +items, err := client.ListByProductComplete(ctx, id, productapi.DefaultListByProductOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/productapi/client.go b/resource-manager/apimanagement/2024-05-01/productapi/client.go new file mode 100644 index 00000000000..1e0b184ff57 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapi/client.go @@ -0,0 +1,26 @@ +package productapi + +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 ProductApiClient struct { + Client *resourcemanager.Client +} + +func NewProductApiClientWithBaseURI(sdkApi sdkEnv.Api) (*ProductApiClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "productapi", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ProductApiClient: %+v", err) + } + + return &ProductApiClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/productapi/constants.go b/resource-manager/apimanagement/2024-05-01/productapi/constants.go new file mode 100644 index 00000000000..5102d6bf3c4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapi/constants.go @@ -0,0 +1,195 @@ +package productapi + +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 ApiType string + +const ( + ApiTypeGraphql ApiType = "graphql" + ApiTypeGrpc ApiType = "grpc" + ApiTypeHTTP ApiType = "http" + ApiTypeOdata ApiType = "odata" + ApiTypeSoap ApiType = "soap" + ApiTypeWebsocket ApiType = "websocket" +) + +func PossibleValuesForApiType() []string { + return []string{ + string(ApiTypeGraphql), + string(ApiTypeGrpc), + string(ApiTypeHTTP), + string(ApiTypeOdata), + string(ApiTypeSoap), + string(ApiTypeWebsocket), + } +} + +func (s *ApiType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseApiType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseApiType(input string) (*ApiType, error) { + vals := map[string]ApiType{ + "graphql": ApiTypeGraphql, + "grpc": ApiTypeGrpc, + "http": ApiTypeHTTP, + "odata": ApiTypeOdata, + "soap": ApiTypeSoap, + "websocket": ApiTypeWebsocket, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ApiType(input) + return &out, nil +} + +type BearerTokenSendingMethods string + +const ( + BearerTokenSendingMethodsAuthorizationHeader BearerTokenSendingMethods = "authorizationHeader" + BearerTokenSendingMethodsQuery BearerTokenSendingMethods = "query" +) + +func PossibleValuesForBearerTokenSendingMethods() []string { + return []string{ + string(BearerTokenSendingMethodsAuthorizationHeader), + string(BearerTokenSendingMethodsQuery), + } +} + +func (s *BearerTokenSendingMethods) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBearerTokenSendingMethods(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBearerTokenSendingMethods(input string) (*BearerTokenSendingMethods, error) { + vals := map[string]BearerTokenSendingMethods{ + "authorizationheader": BearerTokenSendingMethodsAuthorizationHeader, + "query": BearerTokenSendingMethodsQuery, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BearerTokenSendingMethods(input) + return &out, nil +} + +type Protocol string + +const ( + ProtocolHTTP Protocol = "http" + ProtocolHTTPS Protocol = "https" + ProtocolWs Protocol = "ws" + ProtocolWss Protocol = "wss" +) + +func PossibleValuesForProtocol() []string { + return []string{ + string(ProtocolHTTP), + string(ProtocolHTTPS), + string(ProtocolWs), + string(ProtocolWss), + } +} + +func (s *Protocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProtocol(input string) (*Protocol, error) { + vals := map[string]Protocol{ + "http": ProtocolHTTP, + "https": ProtocolHTTPS, + "ws": ProtocolWs, + "wss": ProtocolWss, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Protocol(input) + return &out, nil +} + +type VersioningScheme string + +const ( + VersioningSchemeHeader VersioningScheme = "Header" + VersioningSchemeQuery VersioningScheme = "Query" + VersioningSchemeSegment VersioningScheme = "Segment" +) + +func PossibleValuesForVersioningScheme() []string { + return []string{ + string(VersioningSchemeHeader), + string(VersioningSchemeQuery), + string(VersioningSchemeSegment), + } +} + +func (s *VersioningScheme) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVersioningScheme(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVersioningScheme(input string) (*VersioningScheme, error) { + vals := map[string]VersioningScheme{ + "header": VersioningSchemeHeader, + "query": VersioningSchemeQuery, + "segment": VersioningSchemeSegment, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VersioningScheme(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/productapi/id_product.go b/resource-manager/apimanagement/2024-05-01/productapi/id_product.go new file mode 100644 index 00000000000..76244a5f127 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapi/id_product.go @@ -0,0 +1,139 @@ +package productapi + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProductId{}) +} + +var _ resourceids.ResourceId = &ProductId{} + +// ProductId is a struct representing the Resource ID for a Product +type ProductId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ProductId string +} + +// NewProductID returns a new ProductId struct +func NewProductID(subscriptionId string, resourceGroupName string, serviceName string, productId string) ProductId { + return ProductId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ProductId: productId, + } +} + +// ParseProductID parses 'input' into a ProductId +func ParseProductID(input string) (*ProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProductIDInsensitively parses 'input' case-insensitively into a ProductId +// note: this method should only be used for API response data and not user input +func ParseProductIDInsensitively(input string) (*ProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProductId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ProductId, ok = input.Parsed["productId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "productId", input) + } + + return nil +} + +// ValidateProductID checks that 'input' can be parsed as a Product ID +func ValidateProductID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseProductID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Product ID +func (id ProductId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/products/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ProductId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Product ID +func (id ProductId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticProducts", "products", "products"), + resourceids.UserSpecifiedSegment("productId", "productIdValue"), + } +} + +// String returns a human-readable description of this Product ID +func (id ProductId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Product: %q", id.ProductId), + } + return fmt.Sprintf("Product (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/productapi/id_product_test.go b/resource-manager/apimanagement/2024-05-01/productapi/id_product_test.go new file mode 100644 index 00000000000..9b46fbfe1d9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapi/id_product_test.go @@ -0,0 +1,327 @@ +package productapi + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ProductId{} + +func TestNewProductID(t *testing.T) { + id := NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ProductId != "productIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProductId'", id.ProductId, "productIdValue") + } +} + +func TestFormatProductID(t *testing.T) { + actual := NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProductID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestParseProductIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ProductId: "pRoDuCtIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestSegmentsForProductId(t *testing.T) { + segments := ProductId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProductId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/productapi/id_productapi.go b/resource-manager/apimanagement/2024-05-01/productapi/id_productapi.go new file mode 100644 index 00000000000..ac92947ceaf --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapi/id_productapi.go @@ -0,0 +1,148 @@ +package productapi + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProductApiId{}) +} + +var _ resourceids.ResourceId = &ProductApiId{} + +// ProductApiId is a struct representing the Resource ID for a Product Api +type ProductApiId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ProductId string + ApiId string +} + +// NewProductApiID returns a new ProductApiId struct +func NewProductApiID(subscriptionId string, resourceGroupName string, serviceName string, productId string, apiId string) ProductApiId { + return ProductApiId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ProductId: productId, + ApiId: apiId, + } +} + +// ParseProductApiID parses 'input' into a ProductApiId +func ParseProductApiID(input string) (*ProductApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductApiId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProductApiIDInsensitively parses 'input' case-insensitively into a ProductApiId +// note: this method should only be used for API response data and not user input +func ParseProductApiIDInsensitively(input string) (*ProductApiId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductApiId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductApiId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProductApiId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ProductId, ok = input.Parsed["productId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "productId", input) + } + + if id.ApiId, ok = input.Parsed["apiId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiId", input) + } + + return nil +} + +// ValidateProductApiID checks that 'input' can be parsed as a Product Api ID +func ValidateProductApiID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseProductApiID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Product Api ID +func (id ProductApiId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/products/%s/apis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ProductId, id.ApiId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Product Api ID +func (id ProductApiId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticProducts", "products", "products"), + resourceids.UserSpecifiedSegment("productId", "productIdValue"), + resourceids.StaticSegment("staticApis", "apis", "apis"), + resourceids.UserSpecifiedSegment("apiId", "apiIdValue"), + } +} + +// String returns a human-readable description of this Product Api ID +func (id ProductApiId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Product: %q", id.ProductId), + fmt.Sprintf("Api: %q", id.ApiId), + } + return fmt.Sprintf("Product Api (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/productapi/id_productapi_test.go b/resource-manager/apimanagement/2024-05-01/productapi/id_productapi_test.go new file mode 100644 index 00000000000..b586156b757 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapi/id_productapi_test.go @@ -0,0 +1,372 @@ +package productapi + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ProductApiId{} + +func TestNewProductApiID(t *testing.T) { + id := NewProductApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "apiIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ProductId != "productIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProductId'", id.ProductId, "productIdValue") + } + + if id.ApiId != "apiIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiId'", id.ApiId, "apiIdValue") + } +} + +func TestFormatProductApiID(t *testing.T) { + actual := NewProductApiID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "apiIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/apis/apiIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProductApiID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/apis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/apis/apiIdValue", + Expected: &ProductApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/apis/apiIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductApiID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestParseProductApiIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductApiId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/apis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/aPiS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/apis/apiIdValue", + Expected: &ProductApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + ApiId: "apiIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/apis/apiIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/aPiS/aPiIdVaLuE", + Expected: &ProductApiId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ProductId: "pRoDuCtIdVaLuE", + ApiId: "aPiIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/aPiS/aPiIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductApiIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + if actual.ApiId != v.Expected.ApiId { + t.Fatalf("Expected %q but got %q for ApiId", v.Expected.ApiId, actual.ApiId) + } + + } +} + +func TestSegmentsForProductApiId(t *testing.T) { + segments := ProductApiId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProductApiId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/productapi/method_checkentityexists.go b/resource-manager/apimanagement/2024-05-01/productapi/method_checkentityexists.go new file mode 100644 index 00000000000..69d91adfcef --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapi/method_checkentityexists.go @@ -0,0 +1,46 @@ +package productapi + +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 CheckEntityExistsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CheckEntityExists ... +func (c ProductApiClient) CheckEntityExists(ctx context.Context, id ProductApiId) (result CheckEntityExistsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productapi/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/productapi/method_createorupdate.go new file mode 100644 index 00000000000..e27e2ed31a5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapi/method_createorupdate.go @@ -0,0 +1,55 @@ +package productapi + +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 *ApiContract +} + +// CreateOrUpdate ... +func (c ProductApiClient) CreateOrUpdate(ctx context.Context, id ProductApiId) (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 + } + + 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 ApiContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productapi/method_delete.go b/resource-manager/apimanagement/2024-05-01/productapi/method_delete.go new file mode 100644 index 00000000000..da188ce2e72 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapi/method_delete.go @@ -0,0 +1,47 @@ +package productapi + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ProductApiClient) Delete(ctx context.Context, id ProductApiId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productapi/method_listbyproduct.go b/resource-manager/apimanagement/2024-05-01/productapi/method_listbyproduct.go new file mode 100644 index 00000000000..c06016675dd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapi/method_listbyproduct.go @@ -0,0 +1,141 @@ +package productapi + +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 ListByProductOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ApiContract +} + +type ListByProductCompleteResult struct { + LatestHttpResponse *http.Response + Items []ApiContract +} + +type ListByProductOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByProductOperationOptions() ListByProductOperationOptions { + return ListByProductOperationOptions{} +} + +func (o ListByProductOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByProductOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByProductOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByProductCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByProductCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByProduct ... +func (c ProductApiClient) ListByProduct(ctx context.Context, id ProductId, options ListByProductOperationOptions) (result ListByProductOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByProductCustomPager{}, + Path: fmt.Sprintf("%s/apis", 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 *[]ApiContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByProductComplete retrieves all the results into a single object +func (c ProductApiClient) ListByProductComplete(ctx context.Context, id ProductId, options ListByProductOperationOptions) (ListByProductCompleteResult, error) { + return c.ListByProductCompleteMatchingPredicate(ctx, id, options, ApiContractOperationPredicate{}) +} + +// ListByProductCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProductApiClient) ListByProductCompleteMatchingPredicate(ctx context.Context, id ProductId, options ListByProductOperationOptions, predicate ApiContractOperationPredicate) (result ListByProductCompleteResult, err error) { + items := make([]ApiContract, 0) + + resp, err := c.ListByProduct(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByProductCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productapi/model_apicontactinformation.go b/resource-manager/apimanagement/2024-05-01/productapi/model_apicontactinformation.go new file mode 100644 index 00000000000..431b237a671 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapi/model_apicontactinformation.go @@ -0,0 +1,10 @@ +package productapi + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiContactInformation struct { + Email *string `json:"email,omitempty"` + Name *string `json:"name,omitempty"` + Url *string `json:"url,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productapi/model_apicontract.go b/resource-manager/apimanagement/2024-05-01/productapi/model_apicontract.go new file mode 100644 index 00000000000..e572fdbd27c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapi/model_apicontract.go @@ -0,0 +1,11 @@ +package productapi + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ApiContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productapi/model_apicontractproperties.go b/resource-manager/apimanagement/2024-05-01/productapi/model_apicontractproperties.go new file mode 100644 index 00000000000..ff4acc2668f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapi/model_apicontractproperties.go @@ -0,0 +1,29 @@ +package productapi + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiContractProperties struct { + ApiRevision *string `json:"apiRevision,omitempty"` + ApiRevisionDescription *string `json:"apiRevisionDescription,omitempty"` + ApiVersion *string `json:"apiVersion,omitempty"` + ApiVersionDescription *string `json:"apiVersionDescription,omitempty"` + ApiVersionSet *ApiVersionSetContractDetails `json:"apiVersionSet,omitempty"` + ApiVersionSetId *string `json:"apiVersionSetId,omitempty"` + AuthenticationSettings *AuthenticationSettingsContract `json:"authenticationSettings,omitempty"` + Contact *ApiContactInformation `json:"contact,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + IsCurrent *bool `json:"isCurrent,omitempty"` + IsOnline *bool `json:"isOnline,omitempty"` + License *ApiLicenseInformation `json:"license,omitempty"` + Path string `json:"path"` + Protocols *[]Protocol `json:"protocols,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + ServiceUrl *string `json:"serviceUrl,omitempty"` + SourceApiId *string `json:"sourceApiId,omitempty"` + SubscriptionKeyParameterNames *SubscriptionKeyParameterNamesContract `json:"subscriptionKeyParameterNames,omitempty"` + SubscriptionRequired *bool `json:"subscriptionRequired,omitempty"` + TermsOfServiceUrl *string `json:"termsOfServiceUrl,omitempty"` + Type *ApiType `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productapi/model_apilicenseinformation.go b/resource-manager/apimanagement/2024-05-01/productapi/model_apilicenseinformation.go new file mode 100644 index 00000000000..f5e72e56e41 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapi/model_apilicenseinformation.go @@ -0,0 +1,9 @@ +package productapi + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiLicenseInformation struct { + Name *string `json:"name,omitempty"` + Url *string `json:"url,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productapi/model_apiversionsetcontractdetails.go b/resource-manager/apimanagement/2024-05-01/productapi/model_apiversionsetcontractdetails.go new file mode 100644 index 00000000000..8c641b33a98 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapi/model_apiversionsetcontractdetails.go @@ -0,0 +1,13 @@ +package productapi + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiVersionSetContractDetails struct { + Description *string `json:"description,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + VersionHeaderName *string `json:"versionHeaderName,omitempty"` + VersionQueryName *string `json:"versionQueryName,omitempty"` + VersioningScheme *VersioningScheme `json:"versioningScheme,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productapi/model_authenticationsettingscontract.go b/resource-manager/apimanagement/2024-05-01/productapi/model_authenticationsettingscontract.go new file mode 100644 index 00000000000..f47d2bac846 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapi/model_authenticationsettingscontract.go @@ -0,0 +1,11 @@ +package productapi + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthenticationSettingsContract struct { + OAuth2 *OAuth2AuthenticationSettingsContract `json:"oAuth2,omitempty"` + OAuth2AuthenticationSettings *[]OAuth2AuthenticationSettingsContract `json:"oAuth2AuthenticationSettings,omitempty"` + Openid *OpenIdAuthenticationSettingsContract `json:"openid,omitempty"` + OpenidAuthenticationSettings *[]OpenIdAuthenticationSettingsContract `json:"openidAuthenticationSettings,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productapi/model_oauth2authenticationsettingscontract.go b/resource-manager/apimanagement/2024-05-01/productapi/model_oauth2authenticationsettingscontract.go new file mode 100644 index 00000000000..71d199bd550 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapi/model_oauth2authenticationsettingscontract.go @@ -0,0 +1,9 @@ +package productapi + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OAuth2AuthenticationSettingsContract struct { + AuthorizationServerId *string `json:"authorizationServerId,omitempty"` + Scope *string `json:"scope,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productapi/model_openidauthenticationsettingscontract.go b/resource-manager/apimanagement/2024-05-01/productapi/model_openidauthenticationsettingscontract.go new file mode 100644 index 00000000000..3117a33ca1b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapi/model_openidauthenticationsettingscontract.go @@ -0,0 +1,9 @@ +package productapi + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OpenIdAuthenticationSettingsContract struct { + BearerTokenSendingMethods *[]BearerTokenSendingMethods `json:"bearerTokenSendingMethods,omitempty"` + OpenidProviderId *string `json:"openidProviderId,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productapi/model_subscriptionkeyparameternamescontract.go b/resource-manager/apimanagement/2024-05-01/productapi/model_subscriptionkeyparameternamescontract.go new file mode 100644 index 00000000000..15514f68803 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapi/model_subscriptionkeyparameternamescontract.go @@ -0,0 +1,9 @@ +package productapi + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionKeyParameterNamesContract struct { + Header *string `json:"header,omitempty"` + Query *string `json:"query,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productapi/predicates.go b/resource-manager/apimanagement/2024-05-01/productapi/predicates.go new file mode 100644 index 00000000000..291c7d4c7b5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapi/predicates.go @@ -0,0 +1,27 @@ +package productapi + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ApiContractOperationPredicate) Matches(input ApiContract) 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/apimanagement/2024-05-01/productapi/version.go b/resource-manager/apimanagement/2024-05-01/productapi/version.go new file mode 100644 index 00000000000..6cc6e1c47f6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapi/version.go @@ -0,0 +1,12 @@ +package productapi + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/productapi/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/productapilink/README.md b/resource-manager/apimanagement/2024-05-01/productapilink/README.md new file mode 100644 index 00000000000..c2cbedb4f17 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapilink/README.md @@ -0,0 +1,160 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/productapilink` Documentation + +The `productapilink` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/productapilink" +``` + + +### Client Initialization + +```go +client := productapilink.NewProductApiLinkClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ProductApiLinkClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := productapilink.NewProductApiLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "apiLinkIdValue") + +payload := productapilink.ProductApiLinkContract{ + // ... +} + + +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: `ProductApiLinkClient.Delete` + +```go +ctx := context.TODO() +id := productapilink.NewProductApiLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "apiLinkIdValue") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductApiLinkClient.Get` + +```go +ctx := context.TODO() +id := productapilink.NewProductApiLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "apiLinkIdValue") + +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: `ProductApiLinkClient.ListByProduct` + +```go +ctx := context.TODO() +id := productapilink.NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + +// alternatively `client.ListByProduct(ctx, id, productapilink.DefaultListByProductOperationOptions())` can be used to do batched pagination +items, err := client.ListByProductComplete(ctx, id, productapilink.DefaultListByProductOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ProductApiLinkClient.WorkspaceProductApiLinkCreateOrUpdate` + +```go +ctx := context.TODO() +id := productapilink.NewWorkspaceProductApiLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue", "apiLinkIdValue") + +payload := productapilink.ProductApiLinkContract{ + // ... +} + + +read, err := client.WorkspaceProductApiLinkCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductApiLinkClient.WorkspaceProductApiLinkDelete` + +```go +ctx := context.TODO() +id := productapilink.NewWorkspaceProductApiLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue", "apiLinkIdValue") + +read, err := client.WorkspaceProductApiLinkDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductApiLinkClient.WorkspaceProductApiLinkGet` + +```go +ctx := context.TODO() +id := productapilink.NewWorkspaceProductApiLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue", "apiLinkIdValue") + +read, err := client.WorkspaceProductApiLinkGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductApiLinkClient.WorkspaceProductApiLinkListByProduct` + +```go +ctx := context.TODO() +id := productapilink.NewWorkspaceProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue") + +// alternatively `client.WorkspaceProductApiLinkListByProduct(ctx, id, productapilink.DefaultWorkspaceProductApiLinkListByProductOperationOptions())` can be used to do batched pagination +items, err := client.WorkspaceProductApiLinkListByProductComplete(ctx, id, productapilink.DefaultWorkspaceProductApiLinkListByProductOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/productapilink/client.go b/resource-manager/apimanagement/2024-05-01/productapilink/client.go new file mode 100644 index 00000000000..8349188784a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapilink/client.go @@ -0,0 +1,26 @@ +package productapilink + +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 ProductApiLinkClient struct { + Client *resourcemanager.Client +} + +func NewProductApiLinkClientWithBaseURI(sdkApi sdkEnv.Api) (*ProductApiLinkClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "productapilink", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ProductApiLinkClient: %+v", err) + } + + return &ProductApiLinkClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/productapilink/id_product.go b/resource-manager/apimanagement/2024-05-01/productapilink/id_product.go new file mode 100644 index 00000000000..8cc4d71ac4d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapilink/id_product.go @@ -0,0 +1,139 @@ +package productapilink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProductId{}) +} + +var _ resourceids.ResourceId = &ProductId{} + +// ProductId is a struct representing the Resource ID for a Product +type ProductId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ProductId string +} + +// NewProductID returns a new ProductId struct +func NewProductID(subscriptionId string, resourceGroupName string, serviceName string, productId string) ProductId { + return ProductId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ProductId: productId, + } +} + +// ParseProductID parses 'input' into a ProductId +func ParseProductID(input string) (*ProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProductIDInsensitively parses 'input' case-insensitively into a ProductId +// note: this method should only be used for API response data and not user input +func ParseProductIDInsensitively(input string) (*ProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProductId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ProductId, ok = input.Parsed["productId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "productId", input) + } + + return nil +} + +// ValidateProductID checks that 'input' can be parsed as a Product ID +func ValidateProductID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseProductID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Product ID +func (id ProductId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/products/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ProductId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Product ID +func (id ProductId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticProducts", "products", "products"), + resourceids.UserSpecifiedSegment("productId", "productIdValue"), + } +} + +// String returns a human-readable description of this Product ID +func (id ProductId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Product: %q", id.ProductId), + } + return fmt.Sprintf("Product (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/productapilink/id_product_test.go b/resource-manager/apimanagement/2024-05-01/productapilink/id_product_test.go new file mode 100644 index 00000000000..8f5bd8848c4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapilink/id_product_test.go @@ -0,0 +1,327 @@ +package productapilink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ProductId{} + +func TestNewProductID(t *testing.T) { + id := NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ProductId != "productIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProductId'", id.ProductId, "productIdValue") + } +} + +func TestFormatProductID(t *testing.T) { + actual := NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProductID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestParseProductIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ProductId: "pRoDuCtIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestSegmentsForProductId(t *testing.T) { + segments := ProductId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProductId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/productapilink/id_productapilink.go b/resource-manager/apimanagement/2024-05-01/productapilink/id_productapilink.go new file mode 100644 index 00000000000..fe5d70ec31e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapilink/id_productapilink.go @@ -0,0 +1,148 @@ +package productapilink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProductApiLinkId{}) +} + +var _ resourceids.ResourceId = &ProductApiLinkId{} + +// ProductApiLinkId is a struct representing the Resource ID for a Product Api Link +type ProductApiLinkId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ProductId string + ApiLinkId string +} + +// NewProductApiLinkID returns a new ProductApiLinkId struct +func NewProductApiLinkID(subscriptionId string, resourceGroupName string, serviceName string, productId string, apiLinkId string) ProductApiLinkId { + return ProductApiLinkId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ProductId: productId, + ApiLinkId: apiLinkId, + } +} + +// ParseProductApiLinkID parses 'input' into a ProductApiLinkId +func ParseProductApiLinkID(input string) (*ProductApiLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductApiLinkId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductApiLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProductApiLinkIDInsensitively parses 'input' case-insensitively into a ProductApiLinkId +// note: this method should only be used for API response data and not user input +func ParseProductApiLinkIDInsensitively(input string) (*ProductApiLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductApiLinkId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductApiLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProductApiLinkId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ProductId, ok = input.Parsed["productId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "productId", input) + } + + if id.ApiLinkId, ok = input.Parsed["apiLinkId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiLinkId", input) + } + + return nil +} + +// ValidateProductApiLinkID checks that 'input' can be parsed as a Product Api Link ID +func ValidateProductApiLinkID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseProductApiLinkID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Product Api Link ID +func (id ProductApiLinkId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/products/%s/apiLinks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ProductId, id.ApiLinkId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Product Api Link ID +func (id ProductApiLinkId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticProducts", "products", "products"), + resourceids.UserSpecifiedSegment("productId", "productIdValue"), + resourceids.StaticSegment("staticApiLinks", "apiLinks", "apiLinks"), + resourceids.UserSpecifiedSegment("apiLinkId", "apiLinkIdValue"), + } +} + +// String returns a human-readable description of this Product Api Link ID +func (id ProductApiLinkId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Product: %q", id.ProductId), + fmt.Sprintf("Api Link: %q", id.ApiLinkId), + } + return fmt.Sprintf("Product Api Link (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/productapilink/id_productapilink_test.go b/resource-manager/apimanagement/2024-05-01/productapilink/id_productapilink_test.go new file mode 100644 index 00000000000..24d7e18600f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapilink/id_productapilink_test.go @@ -0,0 +1,372 @@ +package productapilink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ProductApiLinkId{} + +func TestNewProductApiLinkID(t *testing.T) { + id := NewProductApiLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "apiLinkIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ProductId != "productIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProductId'", id.ProductId, "productIdValue") + } + + if id.ApiLinkId != "apiLinkIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiLinkId'", id.ApiLinkId, "apiLinkIdValue") + } +} + +func TestFormatProductApiLinkID(t *testing.T) { + actual := NewProductApiLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "apiLinkIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/apiLinks/apiLinkIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProductApiLinkID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductApiLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/apiLinks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/apiLinks/apiLinkIdValue", + Expected: &ProductApiLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + ApiLinkId: "apiLinkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/apiLinks/apiLinkIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductApiLinkID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + if actual.ApiLinkId != v.Expected.ApiLinkId { + t.Fatalf("Expected %q but got %q for ApiLinkId", v.Expected.ApiLinkId, actual.ApiLinkId) + } + + } +} + +func TestParseProductApiLinkIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductApiLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/apiLinks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/aPiLiNkS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/apiLinks/apiLinkIdValue", + Expected: &ProductApiLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + ApiLinkId: "apiLinkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/apiLinks/apiLinkIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/aPiLiNkS/aPiLiNkIdVaLuE", + Expected: &ProductApiLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ProductId: "pRoDuCtIdVaLuE", + ApiLinkId: "aPiLiNkIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/aPiLiNkS/aPiLiNkIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductApiLinkIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + if actual.ApiLinkId != v.Expected.ApiLinkId { + t.Fatalf("Expected %q but got %q for ApiLinkId", v.Expected.ApiLinkId, actual.ApiLinkId) + } + + } +} + +func TestSegmentsForProductApiLinkId(t *testing.T) { + segments := ProductApiLinkId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProductApiLinkId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/productapilink/id_workspaceproduct.go b/resource-manager/apimanagement/2024-05-01/productapilink/id_workspaceproduct.go new file mode 100644 index 00000000000..ded946cf1fa --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapilink/id_workspaceproduct.go @@ -0,0 +1,148 @@ +package productapilink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceProductId{}) +} + +var _ resourceids.ResourceId = &WorkspaceProductId{} + +// WorkspaceProductId is a struct representing the Resource ID for a Workspace Product +type WorkspaceProductId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + ProductId string +} + +// NewWorkspaceProductID returns a new WorkspaceProductId struct +func NewWorkspaceProductID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, productId string) WorkspaceProductId { + return WorkspaceProductId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + ProductId: productId, + } +} + +// ParseWorkspaceProductID parses 'input' into a WorkspaceProductId +func ParseWorkspaceProductID(input string) (*WorkspaceProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceProductId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceProductIDInsensitively parses 'input' case-insensitively into a WorkspaceProductId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceProductIDInsensitively(input string) (*WorkspaceProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceProductId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceProductId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.ProductId, ok = input.Parsed["productId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "productId", input) + } + + return nil +} + +// ValidateWorkspaceProductID checks that 'input' can be parsed as a Workspace Product ID +func ValidateWorkspaceProductID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceProductID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Product ID +func (id WorkspaceProductId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/products/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.ProductId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Product ID +func (id WorkspaceProductId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticProducts", "products", "products"), + resourceids.UserSpecifiedSegment("productId", "productIdValue"), + } +} + +// String returns a human-readable description of this Workspace Product ID +func (id WorkspaceProductId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Product: %q", id.ProductId), + } + return fmt.Sprintf("Workspace Product (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/productapilink/id_workspaceproduct_test.go b/resource-manager/apimanagement/2024-05-01/productapilink/id_workspaceproduct_test.go new file mode 100644 index 00000000000..19bc1fe9db4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapilink/id_workspaceproduct_test.go @@ -0,0 +1,372 @@ +package productapilink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceProductId{} + +func TestNewWorkspaceProductID(t *testing.T) { + id := NewWorkspaceProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.ProductId != "productIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProductId'", id.ProductId, "productIdValue") + } +} + +func TestFormatWorkspaceProductID(t *testing.T) { + actual := NewWorkspaceProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceProductID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue", + Expected: &WorkspaceProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceProductID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestParseWorkspaceProductIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pRoDuCtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue", + Expected: &WorkspaceProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pRoDuCtS/pRoDuCtIdVaLuE", + Expected: &WorkspaceProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + ProductId: "pRoDuCtIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceProductIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestSegmentsForWorkspaceProductId(t *testing.T) { + segments := WorkspaceProductId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceProductId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/productapilink/id_workspaceproductapilink.go b/resource-manager/apimanagement/2024-05-01/productapilink/id_workspaceproductapilink.go new file mode 100644 index 00000000000..efb87f6e00f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapilink/id_workspaceproductapilink.go @@ -0,0 +1,157 @@ +package productapilink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceProductApiLinkId{}) +} + +var _ resourceids.ResourceId = &WorkspaceProductApiLinkId{} + +// WorkspaceProductApiLinkId is a struct representing the Resource ID for a Workspace Product Api Link +type WorkspaceProductApiLinkId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + ProductId string + ApiLinkId string +} + +// NewWorkspaceProductApiLinkID returns a new WorkspaceProductApiLinkId struct +func NewWorkspaceProductApiLinkID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, productId string, apiLinkId string) WorkspaceProductApiLinkId { + return WorkspaceProductApiLinkId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + ProductId: productId, + ApiLinkId: apiLinkId, + } +} + +// ParseWorkspaceProductApiLinkID parses 'input' into a WorkspaceProductApiLinkId +func ParseWorkspaceProductApiLinkID(input string) (*WorkspaceProductApiLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceProductApiLinkId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceProductApiLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceProductApiLinkIDInsensitively parses 'input' case-insensitively into a WorkspaceProductApiLinkId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceProductApiLinkIDInsensitively(input string) (*WorkspaceProductApiLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceProductApiLinkId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceProductApiLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceProductApiLinkId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.ProductId, ok = input.Parsed["productId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "productId", input) + } + + if id.ApiLinkId, ok = input.Parsed["apiLinkId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiLinkId", input) + } + + return nil +} + +// ValidateWorkspaceProductApiLinkID checks that 'input' can be parsed as a Workspace Product Api Link ID +func ValidateWorkspaceProductApiLinkID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceProductApiLinkID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Product Api Link ID +func (id WorkspaceProductApiLinkId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/products/%s/apiLinks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.ProductId, id.ApiLinkId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Product Api Link ID +func (id WorkspaceProductApiLinkId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticProducts", "products", "products"), + resourceids.UserSpecifiedSegment("productId", "productIdValue"), + resourceids.StaticSegment("staticApiLinks", "apiLinks", "apiLinks"), + resourceids.UserSpecifiedSegment("apiLinkId", "apiLinkIdValue"), + } +} + +// String returns a human-readable description of this Workspace Product Api Link ID +func (id WorkspaceProductApiLinkId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Product: %q", id.ProductId), + fmt.Sprintf("Api Link: %q", id.ApiLinkId), + } + return fmt.Sprintf("Workspace Product Api Link (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/productapilink/id_workspaceproductapilink_test.go b/resource-manager/apimanagement/2024-05-01/productapilink/id_workspaceproductapilink_test.go new file mode 100644 index 00000000000..e76e767627b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapilink/id_workspaceproductapilink_test.go @@ -0,0 +1,417 @@ +package productapilink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceProductApiLinkId{} + +func TestNewWorkspaceProductApiLinkID(t *testing.T) { + id := NewWorkspaceProductApiLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue", "apiLinkIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.ProductId != "productIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProductId'", id.ProductId, "productIdValue") + } + + if id.ApiLinkId != "apiLinkIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiLinkId'", id.ApiLinkId, "apiLinkIdValue") + } +} + +func TestFormatWorkspaceProductApiLinkID(t *testing.T) { + actual := NewWorkspaceProductApiLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue", "apiLinkIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue/apiLinks/apiLinkIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceProductApiLinkID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceProductApiLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue/apiLinks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue/apiLinks/apiLinkIdValue", + Expected: &WorkspaceProductApiLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ProductId: "productIdValue", + ApiLinkId: "apiLinkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue/apiLinks/apiLinkIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceProductApiLinkID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + if actual.ApiLinkId != v.Expected.ApiLinkId { + t.Fatalf("Expected %q but got %q for ApiLinkId", v.Expected.ApiLinkId, actual.ApiLinkId) + } + + } +} + +func TestParseWorkspaceProductApiLinkIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceProductApiLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pRoDuCtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pRoDuCtS/pRoDuCtIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue/apiLinks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/aPiLiNkS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue/apiLinks/apiLinkIdValue", + Expected: &WorkspaceProductApiLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ProductId: "productIdValue", + ApiLinkId: "apiLinkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue/apiLinks/apiLinkIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/aPiLiNkS/aPiLiNkIdVaLuE", + Expected: &WorkspaceProductApiLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + ProductId: "pRoDuCtIdVaLuE", + ApiLinkId: "aPiLiNkIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/aPiLiNkS/aPiLiNkIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceProductApiLinkIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + if actual.ApiLinkId != v.Expected.ApiLinkId { + t.Fatalf("Expected %q but got %q for ApiLinkId", v.Expected.ApiLinkId, actual.ApiLinkId) + } + + } +} + +func TestSegmentsForWorkspaceProductApiLinkId(t *testing.T) { + segments := WorkspaceProductApiLinkId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceProductApiLinkId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/productapilink/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/productapilink/method_createorupdate.go new file mode 100644 index 00000000000..e711339b44d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapilink/method_createorupdate.go @@ -0,0 +1,59 @@ +package productapilink + +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 *ProductApiLinkContract +} + +// CreateOrUpdate ... +func (c ProductApiLinkClient) CreateOrUpdate(ctx context.Context, id ProductApiLinkId, input ProductApiLinkContract) (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 ProductApiLinkContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productapilink/method_delete.go b/resource-manager/apimanagement/2024-05-01/productapilink/method_delete.go new file mode 100644 index 00000000000..bce127f5f63 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapilink/method_delete.go @@ -0,0 +1,47 @@ +package productapilink + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ProductApiLinkClient) Delete(ctx context.Context, id ProductApiLinkId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productapilink/method_get.go b/resource-manager/apimanagement/2024-05-01/productapilink/method_get.go new file mode 100644 index 00000000000..6f8bfffa257 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapilink/method_get.go @@ -0,0 +1,54 @@ +package productapilink + +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 *ProductApiLinkContract +} + +// Get ... +func (c ProductApiLinkClient) Get(ctx context.Context, id ProductApiLinkId) (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 ProductApiLinkContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productapilink/method_listbyproduct.go b/resource-manager/apimanagement/2024-05-01/productapilink/method_listbyproduct.go new file mode 100644 index 00000000000..5992341c96a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapilink/method_listbyproduct.go @@ -0,0 +1,141 @@ +package productapilink + +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 ListByProductOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ProductApiLinkContract +} + +type ListByProductCompleteResult struct { + LatestHttpResponse *http.Response + Items []ProductApiLinkContract +} + +type ListByProductOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByProductOperationOptions() ListByProductOperationOptions { + return ListByProductOperationOptions{} +} + +func (o ListByProductOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByProductOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByProductOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByProductCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByProductCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByProduct ... +func (c ProductApiLinkClient) ListByProduct(ctx context.Context, id ProductId, options ListByProductOperationOptions) (result ListByProductOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByProductCustomPager{}, + Path: fmt.Sprintf("%s/apiLinks", 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 *[]ProductApiLinkContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByProductComplete retrieves all the results into a single object +func (c ProductApiLinkClient) ListByProductComplete(ctx context.Context, id ProductId, options ListByProductOperationOptions) (ListByProductCompleteResult, error) { + return c.ListByProductCompleteMatchingPredicate(ctx, id, options, ProductApiLinkContractOperationPredicate{}) +} + +// ListByProductCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProductApiLinkClient) ListByProductCompleteMatchingPredicate(ctx context.Context, id ProductId, options ListByProductOperationOptions, predicate ProductApiLinkContractOperationPredicate) (result ListByProductCompleteResult, err error) { + items := make([]ProductApiLinkContract, 0) + + resp, err := c.ListByProduct(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByProductCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productapilink/method_workspaceproductapilinkcreateorupdate.go b/resource-manager/apimanagement/2024-05-01/productapilink/method_workspaceproductapilinkcreateorupdate.go new file mode 100644 index 00000000000..5c589d27c2b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapilink/method_workspaceproductapilinkcreateorupdate.go @@ -0,0 +1,59 @@ +package productapilink + +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 WorkspaceProductApiLinkCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ProductApiLinkContract +} + +// WorkspaceProductApiLinkCreateOrUpdate ... +func (c ProductApiLinkClient) WorkspaceProductApiLinkCreateOrUpdate(ctx context.Context, id WorkspaceProductApiLinkId, input ProductApiLinkContract) (result WorkspaceProductApiLinkCreateOrUpdateOperationResponse, 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 ProductApiLinkContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productapilink/method_workspaceproductapilinkdelete.go b/resource-manager/apimanagement/2024-05-01/productapilink/method_workspaceproductapilinkdelete.go new file mode 100644 index 00000000000..d94f1eee404 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapilink/method_workspaceproductapilinkdelete.go @@ -0,0 +1,47 @@ +package productapilink + +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 WorkspaceProductApiLinkDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceProductApiLinkDelete ... +func (c ProductApiLinkClient) WorkspaceProductApiLinkDelete(ctx context.Context, id WorkspaceProductApiLinkId) (result WorkspaceProductApiLinkDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productapilink/method_workspaceproductapilinkget.go b/resource-manager/apimanagement/2024-05-01/productapilink/method_workspaceproductapilinkget.go new file mode 100644 index 00000000000..187f5e7ac13 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapilink/method_workspaceproductapilinkget.go @@ -0,0 +1,54 @@ +package productapilink + +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 WorkspaceProductApiLinkGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ProductApiLinkContract +} + +// WorkspaceProductApiLinkGet ... +func (c ProductApiLinkClient) WorkspaceProductApiLinkGet(ctx context.Context, id WorkspaceProductApiLinkId) (result WorkspaceProductApiLinkGetOperationResponse, 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 ProductApiLinkContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productapilink/method_workspaceproductapilinklistbyproduct.go b/resource-manager/apimanagement/2024-05-01/productapilink/method_workspaceproductapilinklistbyproduct.go new file mode 100644 index 00000000000..ca1989e31ec --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapilink/method_workspaceproductapilinklistbyproduct.go @@ -0,0 +1,141 @@ +package productapilink + +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 WorkspaceProductApiLinkListByProductOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ProductApiLinkContract +} + +type WorkspaceProductApiLinkListByProductCompleteResult struct { + LatestHttpResponse *http.Response + Items []ProductApiLinkContract +} + +type WorkspaceProductApiLinkListByProductOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultWorkspaceProductApiLinkListByProductOperationOptions() WorkspaceProductApiLinkListByProductOperationOptions { + return WorkspaceProductApiLinkListByProductOperationOptions{} +} + +func (o WorkspaceProductApiLinkListByProductOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceProductApiLinkListByProductOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceProductApiLinkListByProductOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspaceProductApiLinkListByProductCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceProductApiLinkListByProductCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceProductApiLinkListByProduct ... +func (c ProductApiLinkClient) WorkspaceProductApiLinkListByProduct(ctx context.Context, id WorkspaceProductId, options WorkspaceProductApiLinkListByProductOperationOptions) (result WorkspaceProductApiLinkListByProductOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspaceProductApiLinkListByProductCustomPager{}, + Path: fmt.Sprintf("%s/apiLinks", 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 *[]ProductApiLinkContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceProductApiLinkListByProductComplete retrieves all the results into a single object +func (c ProductApiLinkClient) WorkspaceProductApiLinkListByProductComplete(ctx context.Context, id WorkspaceProductId, options WorkspaceProductApiLinkListByProductOperationOptions) (WorkspaceProductApiLinkListByProductCompleteResult, error) { + return c.WorkspaceProductApiLinkListByProductCompleteMatchingPredicate(ctx, id, options, ProductApiLinkContractOperationPredicate{}) +} + +// WorkspaceProductApiLinkListByProductCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProductApiLinkClient) WorkspaceProductApiLinkListByProductCompleteMatchingPredicate(ctx context.Context, id WorkspaceProductId, options WorkspaceProductApiLinkListByProductOperationOptions, predicate ProductApiLinkContractOperationPredicate) (result WorkspaceProductApiLinkListByProductCompleteResult, err error) { + items := make([]ProductApiLinkContract, 0) + + resp, err := c.WorkspaceProductApiLinkListByProduct(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceProductApiLinkListByProductCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productapilink/model_productapilinkcontract.go b/resource-manager/apimanagement/2024-05-01/productapilink/model_productapilinkcontract.go new file mode 100644 index 00000000000..65afd110b4b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapilink/model_productapilinkcontract.go @@ -0,0 +1,11 @@ +package productapilink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductApiLinkContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ProductApiLinkContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productapilink/model_productapilinkcontractproperties.go b/resource-manager/apimanagement/2024-05-01/productapilink/model_productapilinkcontractproperties.go new file mode 100644 index 00000000000..7e7f951fbb8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapilink/model_productapilinkcontractproperties.go @@ -0,0 +1,8 @@ +package productapilink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductApiLinkContractProperties struct { + ApiId string `json:"apiId"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productapilink/predicates.go b/resource-manager/apimanagement/2024-05-01/productapilink/predicates.go new file mode 100644 index 00000000000..ca8ec58e5cc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapilink/predicates.go @@ -0,0 +1,27 @@ +package productapilink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductApiLinkContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ProductApiLinkContractOperationPredicate) Matches(input ProductApiLinkContract) 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/apimanagement/2024-05-01/productapilink/version.go b/resource-manager/apimanagement/2024-05-01/productapilink/version.go new file mode 100644 index 00000000000..3756c1aa6e7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productapilink/version.go @@ -0,0 +1,12 @@ +package productapilink + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/productapilink/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/productgroup/README.md b/resource-manager/apimanagement/2024-05-01/productgroup/README.md new file mode 100644 index 00000000000..929e56ef228 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgroup/README.md @@ -0,0 +1,85 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/productgroup` Documentation + +The `productgroup` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/productgroup" +``` + + +### Client Initialization + +```go +client := productgroup.NewProductGroupClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ProductGroupClient.CheckEntityExists` + +```go +ctx := context.TODO() +id := productgroup.NewProductGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "groupIdValue") + +read, err := client.CheckEntityExists(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductGroupClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := productgroup.NewProductGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "groupIdValue") + +read, err := client.CreateOrUpdate(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductGroupClient.Delete` + +```go +ctx := context.TODO() +id := productgroup.NewProductGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "groupIdValue") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductGroupClient.ListByProduct` + +```go +ctx := context.TODO() +id := productgroup.NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + +// alternatively `client.ListByProduct(ctx, id, productgroup.DefaultListByProductOperationOptions())` can be used to do batched pagination +items, err := client.ListByProductComplete(ctx, id, productgroup.DefaultListByProductOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/productgroup/client.go b/resource-manager/apimanagement/2024-05-01/productgroup/client.go new file mode 100644 index 00000000000..beb9159e3e3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgroup/client.go @@ -0,0 +1,26 @@ +package productgroup + +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 ProductGroupClient struct { + Client *resourcemanager.Client +} + +func NewProductGroupClientWithBaseURI(sdkApi sdkEnv.Api) (*ProductGroupClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "productgroup", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ProductGroupClient: %+v", err) + } + + return &ProductGroupClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/productgroup/constants.go b/resource-manager/apimanagement/2024-05-01/productgroup/constants.go new file mode 100644 index 00000000000..6ff85f660bd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgroup/constants.go @@ -0,0 +1,54 @@ +package productgroup + +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 GroupType string + +const ( + GroupTypeCustom GroupType = "custom" + GroupTypeExternal GroupType = "external" + GroupTypeSystem GroupType = "system" +) + +func PossibleValuesForGroupType() []string { + return []string{ + string(GroupTypeCustom), + string(GroupTypeExternal), + string(GroupTypeSystem), + } +} + +func (s *GroupType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGroupType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseGroupType(input string) (*GroupType, error) { + vals := map[string]GroupType{ + "custom": GroupTypeCustom, + "external": GroupTypeExternal, + "system": GroupTypeSystem, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := GroupType(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/productgroup/id_product.go b/resource-manager/apimanagement/2024-05-01/productgroup/id_product.go new file mode 100644 index 00000000000..df7d9abbfcd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgroup/id_product.go @@ -0,0 +1,139 @@ +package productgroup + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProductId{}) +} + +var _ resourceids.ResourceId = &ProductId{} + +// ProductId is a struct representing the Resource ID for a Product +type ProductId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ProductId string +} + +// NewProductID returns a new ProductId struct +func NewProductID(subscriptionId string, resourceGroupName string, serviceName string, productId string) ProductId { + return ProductId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ProductId: productId, + } +} + +// ParseProductID parses 'input' into a ProductId +func ParseProductID(input string) (*ProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProductIDInsensitively parses 'input' case-insensitively into a ProductId +// note: this method should only be used for API response data and not user input +func ParseProductIDInsensitively(input string) (*ProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProductId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ProductId, ok = input.Parsed["productId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "productId", input) + } + + return nil +} + +// ValidateProductID checks that 'input' can be parsed as a Product ID +func ValidateProductID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseProductID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Product ID +func (id ProductId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/products/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ProductId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Product ID +func (id ProductId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticProducts", "products", "products"), + resourceids.UserSpecifiedSegment("productId", "productIdValue"), + } +} + +// String returns a human-readable description of this Product ID +func (id ProductId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Product: %q", id.ProductId), + } + return fmt.Sprintf("Product (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/productgroup/id_product_test.go b/resource-manager/apimanagement/2024-05-01/productgroup/id_product_test.go new file mode 100644 index 00000000000..d4b5ad9bb4e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgroup/id_product_test.go @@ -0,0 +1,327 @@ +package productgroup + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ProductId{} + +func TestNewProductID(t *testing.T) { + id := NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ProductId != "productIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProductId'", id.ProductId, "productIdValue") + } +} + +func TestFormatProductID(t *testing.T) { + actual := NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProductID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestParseProductIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ProductId: "pRoDuCtIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestSegmentsForProductId(t *testing.T) { + segments := ProductId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProductId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/productgroup/id_productgroup.go b/resource-manager/apimanagement/2024-05-01/productgroup/id_productgroup.go new file mode 100644 index 00000000000..7ede94a7c7f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgroup/id_productgroup.go @@ -0,0 +1,148 @@ +package productgroup + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProductGroupId{}) +} + +var _ resourceids.ResourceId = &ProductGroupId{} + +// ProductGroupId is a struct representing the Resource ID for a Product Group +type ProductGroupId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ProductId string + GroupId string +} + +// NewProductGroupID returns a new ProductGroupId struct +func NewProductGroupID(subscriptionId string, resourceGroupName string, serviceName string, productId string, groupId string) ProductGroupId { + return ProductGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ProductId: productId, + GroupId: groupId, + } +} + +// ParseProductGroupID parses 'input' into a ProductGroupId +func ParseProductGroupID(input string) (*ProductGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductGroupId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProductGroupIDInsensitively parses 'input' case-insensitively into a ProductGroupId +// note: this method should only be used for API response data and not user input +func ParseProductGroupIDInsensitively(input string) (*ProductGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductGroupId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProductGroupId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ProductId, ok = input.Parsed["productId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "productId", input) + } + + if id.GroupId, ok = input.Parsed["groupId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupId", input) + } + + return nil +} + +// ValidateProductGroupID checks that 'input' can be parsed as a Product Group ID +func ValidateProductGroupID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseProductGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Product Group ID +func (id ProductGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/products/%s/groups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ProductId, id.GroupId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Product Group ID +func (id ProductGroupId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticProducts", "products", "products"), + resourceids.UserSpecifiedSegment("productId", "productIdValue"), + resourceids.StaticSegment("staticGroups", "groups", "groups"), + resourceids.UserSpecifiedSegment("groupId", "groupIdValue"), + } +} + +// String returns a human-readable description of this Product Group ID +func (id ProductGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Product: %q", id.ProductId), + fmt.Sprintf("Group: %q", id.GroupId), + } + return fmt.Sprintf("Product Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/productgroup/id_productgroup_test.go b/resource-manager/apimanagement/2024-05-01/productgroup/id_productgroup_test.go new file mode 100644 index 00000000000..89fce1cdf13 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgroup/id_productgroup_test.go @@ -0,0 +1,372 @@ +package productgroup + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ProductGroupId{} + +func TestNewProductGroupID(t *testing.T) { + id := NewProductGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "groupIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ProductId != "productIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProductId'", id.ProductId, "productIdValue") + } + + if id.GroupId != "groupIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'GroupId'", id.GroupId, "groupIdValue") + } +} + +func TestFormatProductGroupID(t *testing.T) { + actual := NewProductGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "groupIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/groups/groupIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProductGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductGroupId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/groups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/groups/groupIdValue", + Expected: &ProductGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + GroupId: "groupIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/groups/groupIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductGroupID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + if actual.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + } +} + +func TestParseProductGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductGroupId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/groups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/gRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/groups/groupIdValue", + Expected: &ProductGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + GroupId: "groupIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/groups/groupIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/gRoUpS/gRoUpIdVaLuE", + Expected: &ProductGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ProductId: "pRoDuCtIdVaLuE", + GroupId: "gRoUpIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/gRoUpS/gRoUpIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductGroupIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + if actual.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + } +} + +func TestSegmentsForProductGroupId(t *testing.T) { + segments := ProductGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProductGroupId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/productgroup/method_checkentityexists.go b/resource-manager/apimanagement/2024-05-01/productgroup/method_checkentityexists.go new file mode 100644 index 00000000000..fd90f4c41cf --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgroup/method_checkentityexists.go @@ -0,0 +1,46 @@ +package productgroup + +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 CheckEntityExistsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CheckEntityExists ... +func (c ProductGroupClient) CheckEntityExists(ctx context.Context, id ProductGroupId) (result CheckEntityExistsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productgroup/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/productgroup/method_createorupdate.go new file mode 100644 index 00000000000..77cf8dbf10e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgroup/method_createorupdate.go @@ -0,0 +1,55 @@ +package productgroup + +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 *GroupContract +} + +// CreateOrUpdate ... +func (c ProductGroupClient) CreateOrUpdate(ctx context.Context, id ProductGroupId) (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 + } + + 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 GroupContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productgroup/method_delete.go b/resource-manager/apimanagement/2024-05-01/productgroup/method_delete.go new file mode 100644 index 00000000000..3f6b1c8820e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgroup/method_delete.go @@ -0,0 +1,47 @@ +package productgroup + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ProductGroupClient) Delete(ctx context.Context, id ProductGroupId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productgroup/method_listbyproduct.go b/resource-manager/apimanagement/2024-05-01/productgroup/method_listbyproduct.go new file mode 100644 index 00000000000..902f45c4f73 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgroup/method_listbyproduct.go @@ -0,0 +1,141 @@ +package productgroup + +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 ListByProductOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GroupContract +} + +type ListByProductCompleteResult struct { + LatestHttpResponse *http.Response + Items []GroupContract +} + +type ListByProductOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByProductOperationOptions() ListByProductOperationOptions { + return ListByProductOperationOptions{} +} + +func (o ListByProductOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByProductOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByProductOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByProductCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByProductCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByProduct ... +func (c ProductGroupClient) ListByProduct(ctx context.Context, id ProductId, options ListByProductOperationOptions) (result ListByProductOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByProductCustomPager{}, + Path: fmt.Sprintf("%s/groups", 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 *[]GroupContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByProductComplete retrieves all the results into a single object +func (c ProductGroupClient) ListByProductComplete(ctx context.Context, id ProductId, options ListByProductOperationOptions) (ListByProductCompleteResult, error) { + return c.ListByProductCompleteMatchingPredicate(ctx, id, options, GroupContractOperationPredicate{}) +} + +// ListByProductCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProductGroupClient) ListByProductCompleteMatchingPredicate(ctx context.Context, id ProductId, options ListByProductOperationOptions, predicate GroupContractOperationPredicate) (result ListByProductCompleteResult, err error) { + items := make([]GroupContract, 0) + + resp, err := c.ListByProduct(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByProductCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productgroup/model_groupcontract.go b/resource-manager/apimanagement/2024-05-01/productgroup/model_groupcontract.go new file mode 100644 index 00000000000..e2c720afe0c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgroup/model_groupcontract.go @@ -0,0 +1,11 @@ +package productgroup + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *GroupContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productgroup/model_groupcontractproperties.go b/resource-manager/apimanagement/2024-05-01/productgroup/model_groupcontractproperties.go new file mode 100644 index 00000000000..f4dc5d95653 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgroup/model_groupcontractproperties.go @@ -0,0 +1,12 @@ +package productgroup + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupContractProperties struct { + BuiltIn *bool `json:"builtIn,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName string `json:"displayName"` + ExternalId *string `json:"externalId,omitempty"` + Type *GroupType `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productgroup/predicates.go b/resource-manager/apimanagement/2024-05-01/productgroup/predicates.go new file mode 100644 index 00000000000..6d25db13cf9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgroup/predicates.go @@ -0,0 +1,27 @@ +package productgroup + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p GroupContractOperationPredicate) Matches(input GroupContract) 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/apimanagement/2024-05-01/productgroup/version.go b/resource-manager/apimanagement/2024-05-01/productgroup/version.go new file mode 100644 index 00000000000..edf0a207c88 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgroup/version.go @@ -0,0 +1,12 @@ +package productgroup + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/productgroup/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/productgrouplink/README.md b/resource-manager/apimanagement/2024-05-01/productgrouplink/README.md new file mode 100644 index 00000000000..39771f8c3fb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgrouplink/README.md @@ -0,0 +1,160 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/productgrouplink` Documentation + +The `productgrouplink` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/productgrouplink" +``` + + +### Client Initialization + +```go +client := productgrouplink.NewProductGroupLinkClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ProductGroupLinkClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := productgrouplink.NewGroupLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "groupLinkIdValue") + +payload := productgrouplink.ProductGroupLinkContract{ + // ... +} + + +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: `ProductGroupLinkClient.Delete` + +```go +ctx := context.TODO() +id := productgrouplink.NewGroupLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "groupLinkIdValue") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductGroupLinkClient.Get` + +```go +ctx := context.TODO() +id := productgrouplink.NewGroupLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "groupLinkIdValue") + +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: `ProductGroupLinkClient.ListByProduct` + +```go +ctx := context.TODO() +id := productgrouplink.NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + +// alternatively `client.ListByProduct(ctx, id, productgrouplink.DefaultListByProductOperationOptions())` can be used to do batched pagination +items, err := client.ListByProductComplete(ctx, id, productgrouplink.DefaultListByProductOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ProductGroupLinkClient.WorkspaceProductGroupLinkCreateOrUpdate` + +```go +ctx := context.TODO() +id := productgrouplink.NewProductGroupLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue", "groupLinkIdValue") + +payload := productgrouplink.ProductGroupLinkContract{ + // ... +} + + +read, err := client.WorkspaceProductGroupLinkCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductGroupLinkClient.WorkspaceProductGroupLinkDelete` + +```go +ctx := context.TODO() +id := productgrouplink.NewProductGroupLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue", "groupLinkIdValue") + +read, err := client.WorkspaceProductGroupLinkDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductGroupLinkClient.WorkspaceProductGroupLinkGet` + +```go +ctx := context.TODO() +id := productgrouplink.NewProductGroupLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue", "groupLinkIdValue") + +read, err := client.WorkspaceProductGroupLinkGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductGroupLinkClient.WorkspaceProductGroupLinkListByProduct` + +```go +ctx := context.TODO() +id := productgrouplink.NewWorkspaceProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue") + +// alternatively `client.WorkspaceProductGroupLinkListByProduct(ctx, id, productgrouplink.DefaultWorkspaceProductGroupLinkListByProductOperationOptions())` can be used to do batched pagination +items, err := client.WorkspaceProductGroupLinkListByProductComplete(ctx, id, productgrouplink.DefaultWorkspaceProductGroupLinkListByProductOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/productgrouplink/client.go b/resource-manager/apimanagement/2024-05-01/productgrouplink/client.go new file mode 100644 index 00000000000..3528003e35b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgrouplink/client.go @@ -0,0 +1,26 @@ +package productgrouplink + +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 ProductGroupLinkClient struct { + Client *resourcemanager.Client +} + +func NewProductGroupLinkClientWithBaseURI(sdkApi sdkEnv.Api) (*ProductGroupLinkClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "productgrouplink", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ProductGroupLinkClient: %+v", err) + } + + return &ProductGroupLinkClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/productgrouplink/id_grouplink.go b/resource-manager/apimanagement/2024-05-01/productgrouplink/id_grouplink.go new file mode 100644 index 00000000000..c16ddba297b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgrouplink/id_grouplink.go @@ -0,0 +1,148 @@ +package productgrouplink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&GroupLinkId{}) +} + +var _ resourceids.ResourceId = &GroupLinkId{} + +// GroupLinkId is a struct representing the Resource ID for a Group Link +type GroupLinkId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ProductId string + GroupLinkId string +} + +// NewGroupLinkID returns a new GroupLinkId struct +func NewGroupLinkID(subscriptionId string, resourceGroupName string, serviceName string, productId string, groupLinkId string) GroupLinkId { + return GroupLinkId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ProductId: productId, + GroupLinkId: groupLinkId, + } +} + +// ParseGroupLinkID parses 'input' into a GroupLinkId +func ParseGroupLinkID(input string) (*GroupLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&GroupLinkId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GroupLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGroupLinkIDInsensitively parses 'input' case-insensitively into a GroupLinkId +// note: this method should only be used for API response data and not user input +func ParseGroupLinkIDInsensitively(input string) (*GroupLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&GroupLinkId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GroupLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GroupLinkId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ProductId, ok = input.Parsed["productId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "productId", input) + } + + if id.GroupLinkId, ok = input.Parsed["groupLinkId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupLinkId", input) + } + + return nil +} + +// ValidateGroupLinkID checks that 'input' can be parsed as a Group Link ID +func ValidateGroupLinkID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseGroupLinkID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Group Link ID +func (id GroupLinkId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/products/%s/groupLinks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ProductId, id.GroupLinkId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Group Link ID +func (id GroupLinkId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticProducts", "products", "products"), + resourceids.UserSpecifiedSegment("productId", "productIdValue"), + resourceids.StaticSegment("staticGroupLinks", "groupLinks", "groupLinks"), + resourceids.UserSpecifiedSegment("groupLinkId", "groupLinkIdValue"), + } +} + +// String returns a human-readable description of this Group Link ID +func (id GroupLinkId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Product: %q", id.ProductId), + fmt.Sprintf("Group Link: %q", id.GroupLinkId), + } + return fmt.Sprintf("Group Link (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/productgrouplink/id_grouplink_test.go b/resource-manager/apimanagement/2024-05-01/productgrouplink/id_grouplink_test.go new file mode 100644 index 00000000000..3c50bedce83 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgrouplink/id_grouplink_test.go @@ -0,0 +1,372 @@ +package productgrouplink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GroupLinkId{} + +func TestNewGroupLinkID(t *testing.T) { + id := NewGroupLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "groupLinkIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ProductId != "productIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProductId'", id.ProductId, "productIdValue") + } + + if id.GroupLinkId != "groupLinkIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'GroupLinkId'", id.GroupLinkId, "groupLinkIdValue") + } +} + +func TestFormatGroupLinkID(t *testing.T) { + actual := NewGroupLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "groupLinkIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/groupLinks/groupLinkIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGroupLinkID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GroupLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/groupLinks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/groupLinks/groupLinkIdValue", + Expected: &GroupLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + GroupLinkId: "groupLinkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/groupLinks/groupLinkIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGroupLinkID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + if actual.GroupLinkId != v.Expected.GroupLinkId { + t.Fatalf("Expected %q but got %q for GroupLinkId", v.Expected.GroupLinkId, actual.GroupLinkId) + } + + } +} + +func TestParseGroupLinkIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GroupLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/groupLinks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/gRoUpLiNkS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/groupLinks/groupLinkIdValue", + Expected: &GroupLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + GroupLinkId: "groupLinkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/groupLinks/groupLinkIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/gRoUpLiNkS/gRoUpLiNkIdVaLuE", + Expected: &GroupLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ProductId: "pRoDuCtIdVaLuE", + GroupLinkId: "gRoUpLiNkIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/gRoUpLiNkS/gRoUpLiNkIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGroupLinkIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + if actual.GroupLinkId != v.Expected.GroupLinkId { + t.Fatalf("Expected %q but got %q for GroupLinkId", v.Expected.GroupLinkId, actual.GroupLinkId) + } + + } +} + +func TestSegmentsForGroupLinkId(t *testing.T) { + segments := GroupLinkId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GroupLinkId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/productgrouplink/id_product.go b/resource-manager/apimanagement/2024-05-01/productgrouplink/id_product.go new file mode 100644 index 00000000000..ebda99376a6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgrouplink/id_product.go @@ -0,0 +1,139 @@ +package productgrouplink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProductId{}) +} + +var _ resourceids.ResourceId = &ProductId{} + +// ProductId is a struct representing the Resource ID for a Product +type ProductId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ProductId string +} + +// NewProductID returns a new ProductId struct +func NewProductID(subscriptionId string, resourceGroupName string, serviceName string, productId string) ProductId { + return ProductId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ProductId: productId, + } +} + +// ParseProductID parses 'input' into a ProductId +func ParseProductID(input string) (*ProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProductIDInsensitively parses 'input' case-insensitively into a ProductId +// note: this method should only be used for API response data and not user input +func ParseProductIDInsensitively(input string) (*ProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProductId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ProductId, ok = input.Parsed["productId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "productId", input) + } + + return nil +} + +// ValidateProductID checks that 'input' can be parsed as a Product ID +func ValidateProductID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseProductID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Product ID +func (id ProductId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/products/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ProductId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Product ID +func (id ProductId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticProducts", "products", "products"), + resourceids.UserSpecifiedSegment("productId", "productIdValue"), + } +} + +// String returns a human-readable description of this Product ID +func (id ProductId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Product: %q", id.ProductId), + } + return fmt.Sprintf("Product (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/productgrouplink/id_product_test.go b/resource-manager/apimanagement/2024-05-01/productgrouplink/id_product_test.go new file mode 100644 index 00000000000..82b68916179 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgrouplink/id_product_test.go @@ -0,0 +1,327 @@ +package productgrouplink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ProductId{} + +func TestNewProductID(t *testing.T) { + id := NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ProductId != "productIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProductId'", id.ProductId, "productIdValue") + } +} + +func TestFormatProductID(t *testing.T) { + actual := NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProductID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestParseProductIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ProductId: "pRoDuCtIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestSegmentsForProductId(t *testing.T) { + segments := ProductId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProductId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/productgrouplink/id_productgrouplink.go b/resource-manager/apimanagement/2024-05-01/productgrouplink/id_productgrouplink.go new file mode 100644 index 00000000000..b138aa0fbab --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgrouplink/id_productgrouplink.go @@ -0,0 +1,157 @@ +package productgrouplink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProductGroupLinkId{}) +} + +var _ resourceids.ResourceId = &ProductGroupLinkId{} + +// ProductGroupLinkId is a struct representing the Resource ID for a Product Group Link +type ProductGroupLinkId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + ProductId string + GroupLinkId string +} + +// NewProductGroupLinkID returns a new ProductGroupLinkId struct +func NewProductGroupLinkID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, productId string, groupLinkId string) ProductGroupLinkId { + return ProductGroupLinkId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + ProductId: productId, + GroupLinkId: groupLinkId, + } +} + +// ParseProductGroupLinkID parses 'input' into a ProductGroupLinkId +func ParseProductGroupLinkID(input string) (*ProductGroupLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductGroupLinkId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductGroupLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProductGroupLinkIDInsensitively parses 'input' case-insensitively into a ProductGroupLinkId +// note: this method should only be used for API response data and not user input +func ParseProductGroupLinkIDInsensitively(input string) (*ProductGroupLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductGroupLinkId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductGroupLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProductGroupLinkId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.ProductId, ok = input.Parsed["productId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "productId", input) + } + + if id.GroupLinkId, ok = input.Parsed["groupLinkId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupLinkId", input) + } + + return nil +} + +// ValidateProductGroupLinkID checks that 'input' can be parsed as a Product Group Link ID +func ValidateProductGroupLinkID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseProductGroupLinkID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Product Group Link ID +func (id ProductGroupLinkId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/products/%s/groupLinks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.ProductId, id.GroupLinkId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Product Group Link ID +func (id ProductGroupLinkId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticProducts", "products", "products"), + resourceids.UserSpecifiedSegment("productId", "productIdValue"), + resourceids.StaticSegment("staticGroupLinks", "groupLinks", "groupLinks"), + resourceids.UserSpecifiedSegment("groupLinkId", "groupLinkIdValue"), + } +} + +// String returns a human-readable description of this Product Group Link ID +func (id ProductGroupLinkId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Product: %q", id.ProductId), + fmt.Sprintf("Group Link: %q", id.GroupLinkId), + } + return fmt.Sprintf("Product Group Link (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/productgrouplink/id_productgrouplink_test.go b/resource-manager/apimanagement/2024-05-01/productgrouplink/id_productgrouplink_test.go new file mode 100644 index 00000000000..0ef88dd26d0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgrouplink/id_productgrouplink_test.go @@ -0,0 +1,417 @@ +package productgrouplink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ProductGroupLinkId{} + +func TestNewProductGroupLinkID(t *testing.T) { + id := NewProductGroupLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue", "groupLinkIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.ProductId != "productIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProductId'", id.ProductId, "productIdValue") + } + + if id.GroupLinkId != "groupLinkIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'GroupLinkId'", id.GroupLinkId, "groupLinkIdValue") + } +} + +func TestFormatProductGroupLinkID(t *testing.T) { + actual := NewProductGroupLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue", "groupLinkIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue/groupLinks/groupLinkIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProductGroupLinkID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductGroupLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue/groupLinks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue/groupLinks/groupLinkIdValue", + Expected: &ProductGroupLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ProductId: "productIdValue", + GroupLinkId: "groupLinkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue/groupLinks/groupLinkIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductGroupLinkID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + if actual.GroupLinkId != v.Expected.GroupLinkId { + t.Fatalf("Expected %q but got %q for GroupLinkId", v.Expected.GroupLinkId, actual.GroupLinkId) + } + + } +} + +func TestParseProductGroupLinkIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductGroupLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pRoDuCtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pRoDuCtS/pRoDuCtIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue/groupLinks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/gRoUpLiNkS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue/groupLinks/groupLinkIdValue", + Expected: &ProductGroupLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ProductId: "productIdValue", + GroupLinkId: "groupLinkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue/groupLinks/groupLinkIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/gRoUpLiNkS/gRoUpLiNkIdVaLuE", + Expected: &ProductGroupLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + ProductId: "pRoDuCtIdVaLuE", + GroupLinkId: "gRoUpLiNkIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/gRoUpLiNkS/gRoUpLiNkIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductGroupLinkIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + if actual.GroupLinkId != v.Expected.GroupLinkId { + t.Fatalf("Expected %q but got %q for GroupLinkId", v.Expected.GroupLinkId, actual.GroupLinkId) + } + + } +} + +func TestSegmentsForProductGroupLinkId(t *testing.T) { + segments := ProductGroupLinkId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProductGroupLinkId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/productgrouplink/id_workspaceproduct.go b/resource-manager/apimanagement/2024-05-01/productgrouplink/id_workspaceproduct.go new file mode 100644 index 00000000000..aaddcc46393 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgrouplink/id_workspaceproduct.go @@ -0,0 +1,148 @@ +package productgrouplink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceProductId{}) +} + +var _ resourceids.ResourceId = &WorkspaceProductId{} + +// WorkspaceProductId is a struct representing the Resource ID for a Workspace Product +type WorkspaceProductId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + ProductId string +} + +// NewWorkspaceProductID returns a new WorkspaceProductId struct +func NewWorkspaceProductID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, productId string) WorkspaceProductId { + return WorkspaceProductId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + ProductId: productId, + } +} + +// ParseWorkspaceProductID parses 'input' into a WorkspaceProductId +func ParseWorkspaceProductID(input string) (*WorkspaceProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceProductId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceProductIDInsensitively parses 'input' case-insensitively into a WorkspaceProductId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceProductIDInsensitively(input string) (*WorkspaceProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceProductId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceProductId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.ProductId, ok = input.Parsed["productId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "productId", input) + } + + return nil +} + +// ValidateWorkspaceProductID checks that 'input' can be parsed as a Workspace Product ID +func ValidateWorkspaceProductID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceProductID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Product ID +func (id WorkspaceProductId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/products/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.ProductId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Product ID +func (id WorkspaceProductId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticProducts", "products", "products"), + resourceids.UserSpecifiedSegment("productId", "productIdValue"), + } +} + +// String returns a human-readable description of this Workspace Product ID +func (id WorkspaceProductId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Product: %q", id.ProductId), + } + return fmt.Sprintf("Workspace Product (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/productgrouplink/id_workspaceproduct_test.go b/resource-manager/apimanagement/2024-05-01/productgrouplink/id_workspaceproduct_test.go new file mode 100644 index 00000000000..21634ce13e4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgrouplink/id_workspaceproduct_test.go @@ -0,0 +1,372 @@ +package productgrouplink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceProductId{} + +func TestNewWorkspaceProductID(t *testing.T) { + id := NewWorkspaceProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.ProductId != "productIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProductId'", id.ProductId, "productIdValue") + } +} + +func TestFormatWorkspaceProductID(t *testing.T) { + actual := NewWorkspaceProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceProductID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue", + Expected: &WorkspaceProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceProductID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestParseWorkspaceProductIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pRoDuCtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue", + Expected: &WorkspaceProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pRoDuCtS/pRoDuCtIdVaLuE", + Expected: &WorkspaceProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + ProductId: "pRoDuCtIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceProductIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestSegmentsForWorkspaceProductId(t *testing.T) { + segments := WorkspaceProductId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceProductId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/productgrouplink/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/productgrouplink/method_createorupdate.go new file mode 100644 index 00000000000..c69607c76c0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgrouplink/method_createorupdate.go @@ -0,0 +1,59 @@ +package productgrouplink + +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 *ProductGroupLinkContract +} + +// CreateOrUpdate ... +func (c ProductGroupLinkClient) CreateOrUpdate(ctx context.Context, id GroupLinkId, input ProductGroupLinkContract) (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 ProductGroupLinkContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productgrouplink/method_delete.go b/resource-manager/apimanagement/2024-05-01/productgrouplink/method_delete.go new file mode 100644 index 00000000000..301b067b1f4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgrouplink/method_delete.go @@ -0,0 +1,47 @@ +package productgrouplink + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ProductGroupLinkClient) Delete(ctx context.Context, id GroupLinkId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productgrouplink/method_get.go b/resource-manager/apimanagement/2024-05-01/productgrouplink/method_get.go new file mode 100644 index 00000000000..504db1fe876 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgrouplink/method_get.go @@ -0,0 +1,54 @@ +package productgrouplink + +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 *ProductGroupLinkContract +} + +// Get ... +func (c ProductGroupLinkClient) Get(ctx context.Context, id GroupLinkId) (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 ProductGroupLinkContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productgrouplink/method_listbyproduct.go b/resource-manager/apimanagement/2024-05-01/productgrouplink/method_listbyproduct.go new file mode 100644 index 00000000000..84edbb8b0f2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgrouplink/method_listbyproduct.go @@ -0,0 +1,141 @@ +package productgrouplink + +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 ListByProductOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ProductGroupLinkContract +} + +type ListByProductCompleteResult struct { + LatestHttpResponse *http.Response + Items []ProductGroupLinkContract +} + +type ListByProductOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByProductOperationOptions() ListByProductOperationOptions { + return ListByProductOperationOptions{} +} + +func (o ListByProductOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByProductOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByProductOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByProductCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByProductCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByProduct ... +func (c ProductGroupLinkClient) ListByProduct(ctx context.Context, id ProductId, options ListByProductOperationOptions) (result ListByProductOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByProductCustomPager{}, + Path: fmt.Sprintf("%s/groupLinks", 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 *[]ProductGroupLinkContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByProductComplete retrieves all the results into a single object +func (c ProductGroupLinkClient) ListByProductComplete(ctx context.Context, id ProductId, options ListByProductOperationOptions) (ListByProductCompleteResult, error) { + return c.ListByProductCompleteMatchingPredicate(ctx, id, options, ProductGroupLinkContractOperationPredicate{}) +} + +// ListByProductCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProductGroupLinkClient) ListByProductCompleteMatchingPredicate(ctx context.Context, id ProductId, options ListByProductOperationOptions, predicate ProductGroupLinkContractOperationPredicate) (result ListByProductCompleteResult, err error) { + items := make([]ProductGroupLinkContract, 0) + + resp, err := c.ListByProduct(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByProductCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productgrouplink/method_workspaceproductgrouplinkcreateorupdate.go b/resource-manager/apimanagement/2024-05-01/productgrouplink/method_workspaceproductgrouplinkcreateorupdate.go new file mode 100644 index 00000000000..1819eda2722 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgrouplink/method_workspaceproductgrouplinkcreateorupdate.go @@ -0,0 +1,59 @@ +package productgrouplink + +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 WorkspaceProductGroupLinkCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ProductGroupLinkContract +} + +// WorkspaceProductGroupLinkCreateOrUpdate ... +func (c ProductGroupLinkClient) WorkspaceProductGroupLinkCreateOrUpdate(ctx context.Context, id ProductGroupLinkId, input ProductGroupLinkContract) (result WorkspaceProductGroupLinkCreateOrUpdateOperationResponse, 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 ProductGroupLinkContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productgrouplink/method_workspaceproductgrouplinkdelete.go b/resource-manager/apimanagement/2024-05-01/productgrouplink/method_workspaceproductgrouplinkdelete.go new file mode 100644 index 00000000000..b91af3968d3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgrouplink/method_workspaceproductgrouplinkdelete.go @@ -0,0 +1,47 @@ +package productgrouplink + +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 WorkspaceProductGroupLinkDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceProductGroupLinkDelete ... +func (c ProductGroupLinkClient) WorkspaceProductGroupLinkDelete(ctx context.Context, id ProductGroupLinkId) (result WorkspaceProductGroupLinkDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productgrouplink/method_workspaceproductgrouplinkget.go b/resource-manager/apimanagement/2024-05-01/productgrouplink/method_workspaceproductgrouplinkget.go new file mode 100644 index 00000000000..ee43233ffa6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgrouplink/method_workspaceproductgrouplinkget.go @@ -0,0 +1,54 @@ +package productgrouplink + +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 WorkspaceProductGroupLinkGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ProductGroupLinkContract +} + +// WorkspaceProductGroupLinkGet ... +func (c ProductGroupLinkClient) WorkspaceProductGroupLinkGet(ctx context.Context, id ProductGroupLinkId) (result WorkspaceProductGroupLinkGetOperationResponse, 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 ProductGroupLinkContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productgrouplink/method_workspaceproductgrouplinklistbyproduct.go b/resource-manager/apimanagement/2024-05-01/productgrouplink/method_workspaceproductgrouplinklistbyproduct.go new file mode 100644 index 00000000000..f337fc0d196 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgrouplink/method_workspaceproductgrouplinklistbyproduct.go @@ -0,0 +1,141 @@ +package productgrouplink + +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 WorkspaceProductGroupLinkListByProductOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ProductGroupLinkContract +} + +type WorkspaceProductGroupLinkListByProductCompleteResult struct { + LatestHttpResponse *http.Response + Items []ProductGroupLinkContract +} + +type WorkspaceProductGroupLinkListByProductOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultWorkspaceProductGroupLinkListByProductOperationOptions() WorkspaceProductGroupLinkListByProductOperationOptions { + return WorkspaceProductGroupLinkListByProductOperationOptions{} +} + +func (o WorkspaceProductGroupLinkListByProductOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceProductGroupLinkListByProductOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceProductGroupLinkListByProductOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspaceProductGroupLinkListByProductCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceProductGroupLinkListByProductCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceProductGroupLinkListByProduct ... +func (c ProductGroupLinkClient) WorkspaceProductGroupLinkListByProduct(ctx context.Context, id WorkspaceProductId, options WorkspaceProductGroupLinkListByProductOperationOptions) (result WorkspaceProductGroupLinkListByProductOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspaceProductGroupLinkListByProductCustomPager{}, + Path: fmt.Sprintf("%s/groupLinks", 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 *[]ProductGroupLinkContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceProductGroupLinkListByProductComplete retrieves all the results into a single object +func (c ProductGroupLinkClient) WorkspaceProductGroupLinkListByProductComplete(ctx context.Context, id WorkspaceProductId, options WorkspaceProductGroupLinkListByProductOperationOptions) (WorkspaceProductGroupLinkListByProductCompleteResult, error) { + return c.WorkspaceProductGroupLinkListByProductCompleteMatchingPredicate(ctx, id, options, ProductGroupLinkContractOperationPredicate{}) +} + +// WorkspaceProductGroupLinkListByProductCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProductGroupLinkClient) WorkspaceProductGroupLinkListByProductCompleteMatchingPredicate(ctx context.Context, id WorkspaceProductId, options WorkspaceProductGroupLinkListByProductOperationOptions, predicate ProductGroupLinkContractOperationPredicate) (result WorkspaceProductGroupLinkListByProductCompleteResult, err error) { + items := make([]ProductGroupLinkContract, 0) + + resp, err := c.WorkspaceProductGroupLinkListByProduct(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceProductGroupLinkListByProductCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productgrouplink/model_productgrouplinkcontract.go b/resource-manager/apimanagement/2024-05-01/productgrouplink/model_productgrouplinkcontract.go new file mode 100644 index 00000000000..3399493a479 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgrouplink/model_productgrouplinkcontract.go @@ -0,0 +1,11 @@ +package productgrouplink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductGroupLinkContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ProductGroupLinkContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productgrouplink/model_productgrouplinkcontractproperties.go b/resource-manager/apimanagement/2024-05-01/productgrouplink/model_productgrouplinkcontractproperties.go new file mode 100644 index 00000000000..8cfe9be80ca --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgrouplink/model_productgrouplinkcontractproperties.go @@ -0,0 +1,8 @@ +package productgrouplink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductGroupLinkContractProperties struct { + GroupId string `json:"groupId"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productgrouplink/predicates.go b/resource-manager/apimanagement/2024-05-01/productgrouplink/predicates.go new file mode 100644 index 00000000000..6ba261bbd58 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgrouplink/predicates.go @@ -0,0 +1,27 @@ +package productgrouplink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductGroupLinkContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ProductGroupLinkContractOperationPredicate) Matches(input ProductGroupLinkContract) 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/apimanagement/2024-05-01/productgrouplink/version.go b/resource-manager/apimanagement/2024-05-01/productgrouplink/version.go new file mode 100644 index 00000000000..59ca32eefe0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productgrouplink/version.go @@ -0,0 +1,12 @@ +package productgrouplink + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/productgrouplink/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/productpolicy/README.md b/resource-manager/apimanagement/2024-05-01/productpolicy/README.md new file mode 100644 index 00000000000..49123c1a0f0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productpolicy/README.md @@ -0,0 +1,192 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/productpolicy` Documentation + +The `productpolicy` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/productpolicy" +``` + + +### Client Initialization + +```go +client := productpolicy.NewProductPolicyClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ProductPolicyClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := productpolicy.NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + +payload := productpolicy.PolicyContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, productpolicy.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductPolicyClient.Delete` + +```go +ctx := context.TODO() +id := productpolicy.NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + +read, err := client.Delete(ctx, id, productpolicy.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductPolicyClient.Get` + +```go +ctx := context.TODO() +id := productpolicy.NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + +read, err := client.Get(ctx, id, productpolicy.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductPolicyClient.GetEntityTag` + +```go +ctx := context.TODO() +id := productpolicy.NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductPolicyClient.ListByProduct` + +```go +ctx := context.TODO() +id := productpolicy.NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + +// alternatively `client.ListByProduct(ctx, id)` can be used to do batched pagination +items, err := client.ListByProductComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ProductPolicyClient.WorkspaceProductPolicyCreateOrUpdate` + +```go +ctx := context.TODO() +id := productpolicy.NewWorkspaceProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue") + +payload := productpolicy.PolicyContract{ + // ... +} + + +read, err := client.WorkspaceProductPolicyCreateOrUpdate(ctx, id, payload, productpolicy.DefaultWorkspaceProductPolicyCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductPolicyClient.WorkspaceProductPolicyDelete` + +```go +ctx := context.TODO() +id := productpolicy.NewWorkspaceProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue") + +read, err := client.WorkspaceProductPolicyDelete(ctx, id, productpolicy.DefaultWorkspaceProductPolicyDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductPolicyClient.WorkspaceProductPolicyGet` + +```go +ctx := context.TODO() +id := productpolicy.NewWorkspaceProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue") + +read, err := client.WorkspaceProductPolicyGet(ctx, id, productpolicy.DefaultWorkspaceProductPolicyGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductPolicyClient.WorkspaceProductPolicyGetEntityTag` + +```go +ctx := context.TODO() +id := productpolicy.NewWorkspaceProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue") + +read, err := client.WorkspaceProductPolicyGetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductPolicyClient.WorkspaceProductPolicyListByProduct` + +```go +ctx := context.TODO() +id := productpolicy.NewWorkspaceProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue") + +// alternatively `client.WorkspaceProductPolicyListByProduct(ctx, id)` can be used to do batched pagination +items, err := client.WorkspaceProductPolicyListByProductComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/productpolicy/client.go b/resource-manager/apimanagement/2024-05-01/productpolicy/client.go new file mode 100644 index 00000000000..e6887574aaa --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productpolicy/client.go @@ -0,0 +1,26 @@ +package productpolicy + +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 ProductPolicyClient struct { + Client *resourcemanager.Client +} + +func NewProductPolicyClientWithBaseURI(sdkApi sdkEnv.Api) (*ProductPolicyClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "productpolicy", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ProductPolicyClient: %+v", err) + } + + return &ProductPolicyClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/productpolicy/constants.go b/resource-manager/apimanagement/2024-05-01/productpolicy/constants.go new file mode 100644 index 00000000000..196b57d596f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productpolicy/constants.go @@ -0,0 +1,98 @@ +package productpolicy + +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 PolicyContentFormat string + +const ( + PolicyContentFormatRawxml PolicyContentFormat = "rawxml" + PolicyContentFormatRawxmlNegativelink PolicyContentFormat = "rawxml-link" + PolicyContentFormatXml PolicyContentFormat = "xml" + PolicyContentFormatXmlNegativelink PolicyContentFormat = "xml-link" +) + +func PossibleValuesForPolicyContentFormat() []string { + return []string{ + string(PolicyContentFormatRawxml), + string(PolicyContentFormatRawxmlNegativelink), + string(PolicyContentFormatXml), + string(PolicyContentFormatXmlNegativelink), + } +} + +func (s *PolicyContentFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePolicyContentFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePolicyContentFormat(input string) (*PolicyContentFormat, error) { + vals := map[string]PolicyContentFormat{ + "rawxml": PolicyContentFormatRawxml, + "rawxml-link": PolicyContentFormatRawxmlNegativelink, + "xml": PolicyContentFormatXml, + "xml-link": PolicyContentFormatXmlNegativelink, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyContentFormat(input) + return &out, nil +} + +type PolicyExportFormat string + +const ( + PolicyExportFormatRawxml PolicyExportFormat = "rawxml" + PolicyExportFormatXml PolicyExportFormat = "xml" +) + +func PossibleValuesForPolicyExportFormat() []string { + return []string{ + string(PolicyExportFormatRawxml), + string(PolicyExportFormatXml), + } +} + +func (s *PolicyExportFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePolicyExportFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePolicyExportFormat(input string) (*PolicyExportFormat, error) { + vals := map[string]PolicyExportFormat{ + "rawxml": PolicyExportFormatRawxml, + "xml": PolicyExportFormatXml, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyExportFormat(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/productpolicy/id_product.go b/resource-manager/apimanagement/2024-05-01/productpolicy/id_product.go new file mode 100644 index 00000000000..1b80a823c26 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productpolicy/id_product.go @@ -0,0 +1,139 @@ +package productpolicy + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProductId{}) +} + +var _ resourceids.ResourceId = &ProductId{} + +// ProductId is a struct representing the Resource ID for a Product +type ProductId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ProductId string +} + +// NewProductID returns a new ProductId struct +func NewProductID(subscriptionId string, resourceGroupName string, serviceName string, productId string) ProductId { + return ProductId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ProductId: productId, + } +} + +// ParseProductID parses 'input' into a ProductId +func ParseProductID(input string) (*ProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProductIDInsensitively parses 'input' case-insensitively into a ProductId +// note: this method should only be used for API response data and not user input +func ParseProductIDInsensitively(input string) (*ProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProductId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ProductId, ok = input.Parsed["productId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "productId", input) + } + + return nil +} + +// ValidateProductID checks that 'input' can be parsed as a Product ID +func ValidateProductID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseProductID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Product ID +func (id ProductId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/products/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ProductId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Product ID +func (id ProductId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticProducts", "products", "products"), + resourceids.UserSpecifiedSegment("productId", "productIdValue"), + } +} + +// String returns a human-readable description of this Product ID +func (id ProductId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Product: %q", id.ProductId), + } + return fmt.Sprintf("Product (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/productpolicy/id_product_test.go b/resource-manager/apimanagement/2024-05-01/productpolicy/id_product_test.go new file mode 100644 index 00000000000..ddb4acb31ae --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productpolicy/id_product_test.go @@ -0,0 +1,327 @@ +package productpolicy + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ProductId{} + +func TestNewProductID(t *testing.T) { + id := NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ProductId != "productIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProductId'", id.ProductId, "productIdValue") + } +} + +func TestFormatProductID(t *testing.T) { + actual := NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProductID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestParseProductIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ProductId: "pRoDuCtIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestSegmentsForProductId(t *testing.T) { + segments := ProductId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProductId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/productpolicy/id_workspaceproduct.go b/resource-manager/apimanagement/2024-05-01/productpolicy/id_workspaceproduct.go new file mode 100644 index 00000000000..de50624b5f9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productpolicy/id_workspaceproduct.go @@ -0,0 +1,148 @@ +package productpolicy + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceProductId{}) +} + +var _ resourceids.ResourceId = &WorkspaceProductId{} + +// WorkspaceProductId is a struct representing the Resource ID for a Workspace Product +type WorkspaceProductId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + ProductId string +} + +// NewWorkspaceProductID returns a new WorkspaceProductId struct +func NewWorkspaceProductID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, productId string) WorkspaceProductId { + return WorkspaceProductId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + ProductId: productId, + } +} + +// ParseWorkspaceProductID parses 'input' into a WorkspaceProductId +func ParseWorkspaceProductID(input string) (*WorkspaceProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceProductId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceProductIDInsensitively parses 'input' case-insensitively into a WorkspaceProductId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceProductIDInsensitively(input string) (*WorkspaceProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceProductId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceProductId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.ProductId, ok = input.Parsed["productId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "productId", input) + } + + return nil +} + +// ValidateWorkspaceProductID checks that 'input' can be parsed as a Workspace Product ID +func ValidateWorkspaceProductID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceProductID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Product ID +func (id WorkspaceProductId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/products/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.ProductId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Product ID +func (id WorkspaceProductId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticProducts", "products", "products"), + resourceids.UserSpecifiedSegment("productId", "productIdValue"), + } +} + +// String returns a human-readable description of this Workspace Product ID +func (id WorkspaceProductId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Product: %q", id.ProductId), + } + return fmt.Sprintf("Workspace Product (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/productpolicy/id_workspaceproduct_test.go b/resource-manager/apimanagement/2024-05-01/productpolicy/id_workspaceproduct_test.go new file mode 100644 index 00000000000..fa645052360 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productpolicy/id_workspaceproduct_test.go @@ -0,0 +1,372 @@ +package productpolicy + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceProductId{} + +func TestNewWorkspaceProductID(t *testing.T) { + id := NewWorkspaceProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.ProductId != "productIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProductId'", id.ProductId, "productIdValue") + } +} + +func TestFormatWorkspaceProductID(t *testing.T) { + actual := NewWorkspaceProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "productIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceProductID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue", + Expected: &WorkspaceProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceProductID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestParseWorkspaceProductIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pRoDuCtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue", + Expected: &WorkspaceProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/products/productIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pRoDuCtS/pRoDuCtIdVaLuE", + Expected: &WorkspaceProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + ProductId: "pRoDuCtIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceProductIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestSegmentsForWorkspaceProductId(t *testing.T) { + segments := WorkspaceProductId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceProductId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/productpolicy/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/productpolicy/method_createorupdate.go new file mode 100644 index 00000000000..923d04859e1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productpolicy/method_createorupdate.go @@ -0,0 +1,88 @@ +package productpolicy + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c ProductPolicyClient) CreateOrUpdate(ctx context.Context, id ProductId, input PolicyContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", 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 PolicyContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productpolicy/method_delete.go b/resource-manager/apimanagement/2024-05-01/productpolicy/method_delete.go new file mode 100644 index 00000000000..36e74215a96 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productpolicy/method_delete.go @@ -0,0 +1,76 @@ +package productpolicy + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c ProductPolicyClient) Delete(ctx context.Context, id ProductId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productpolicy/method_get.go b/resource-manager/apimanagement/2024-05-01/productpolicy/method_get.go new file mode 100644 index 00000000000..b96d87150c2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productpolicy/method_get.go @@ -0,0 +1,83 @@ +package productpolicy + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyContract +} + +type GetOperationOptions struct { + Format *PolicyExportFormat +} + +func DefaultGetOperationOptions() GetOperationOptions { + return GetOperationOptions{} +} + +func (o GetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o GetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o GetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Format != nil { + out.Append("format", fmt.Sprintf("%v", *o.Format)) + } + return &out +} + +// Get ... +func (c ProductPolicyClient) Get(ctx context.Context, id ProductId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", 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 PolicyContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productpolicy/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/productpolicy/method_getentitytag.go new file mode 100644 index 00000000000..3e3787982d6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productpolicy/method_getentitytag.go @@ -0,0 +1,47 @@ +package productpolicy + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c ProductPolicyClient) GetEntityTag(ctx context.Context, id ProductId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: fmt.Sprintf("%s/policies/policy", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productpolicy/method_listbyproduct.go b/resource-manager/apimanagement/2024-05-01/productpolicy/method_listbyproduct.go new file mode 100644 index 00000000000..ebb09de40c2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productpolicy/method_listbyproduct.go @@ -0,0 +1,105 @@ +package productpolicy + +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 ListByProductOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PolicyContract +} + +type ListByProductCompleteResult struct { + LatestHttpResponse *http.Response + Items []PolicyContract +} + +type ListByProductCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByProductCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByProduct ... +func (c ProductPolicyClient) ListByProduct(ctx context.Context, id ProductId) (result ListByProductOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByProductCustomPager{}, + Path: fmt.Sprintf("%s/policies", 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 *[]PolicyContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByProductComplete retrieves all the results into a single object +func (c ProductPolicyClient) ListByProductComplete(ctx context.Context, id ProductId) (ListByProductCompleteResult, error) { + return c.ListByProductCompleteMatchingPredicate(ctx, id, PolicyContractOperationPredicate{}) +} + +// ListByProductCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProductPolicyClient) ListByProductCompleteMatchingPredicate(ctx context.Context, id ProductId, predicate PolicyContractOperationPredicate) (result ListByProductCompleteResult, err error) { + items := make([]PolicyContract, 0) + + resp, err := c.ListByProduct(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByProductCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productpolicy/method_workspaceproductpolicycreateorupdate.go b/resource-manager/apimanagement/2024-05-01/productpolicy/method_workspaceproductpolicycreateorupdate.go new file mode 100644 index 00000000000..9a55b9a739a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productpolicy/method_workspaceproductpolicycreateorupdate.go @@ -0,0 +1,88 @@ +package productpolicy + +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 WorkspaceProductPolicyCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyContract +} + +type WorkspaceProductPolicyCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceProductPolicyCreateOrUpdateOperationOptions() WorkspaceProductPolicyCreateOrUpdateOperationOptions { + return WorkspaceProductPolicyCreateOrUpdateOperationOptions{} +} + +func (o WorkspaceProductPolicyCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceProductPolicyCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceProductPolicyCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceProductPolicyCreateOrUpdate ... +func (c ProductPolicyClient) WorkspaceProductPolicyCreateOrUpdate(ctx context.Context, id WorkspaceProductId, input PolicyContract, options WorkspaceProductPolicyCreateOrUpdateOperationOptions) (result WorkspaceProductPolicyCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", 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 PolicyContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productpolicy/method_workspaceproductpolicydelete.go b/resource-manager/apimanagement/2024-05-01/productpolicy/method_workspaceproductpolicydelete.go new file mode 100644 index 00000000000..a76872c52a7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productpolicy/method_workspaceproductpolicydelete.go @@ -0,0 +1,76 @@ +package productpolicy + +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 WorkspaceProductPolicyDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type WorkspaceProductPolicyDeleteOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceProductPolicyDeleteOperationOptions() WorkspaceProductPolicyDeleteOperationOptions { + return WorkspaceProductPolicyDeleteOperationOptions{} +} + +func (o WorkspaceProductPolicyDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceProductPolicyDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceProductPolicyDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceProductPolicyDelete ... +func (c ProductPolicyClient) WorkspaceProductPolicyDelete(ctx context.Context, id WorkspaceProductId, options WorkspaceProductPolicyDeleteOperationOptions) (result WorkspaceProductPolicyDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productpolicy/method_workspaceproductpolicyget.go b/resource-manager/apimanagement/2024-05-01/productpolicy/method_workspaceproductpolicyget.go new file mode 100644 index 00000000000..cbd5809fb0e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productpolicy/method_workspaceproductpolicyget.go @@ -0,0 +1,83 @@ +package productpolicy + +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 WorkspaceProductPolicyGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyContract +} + +type WorkspaceProductPolicyGetOperationOptions struct { + Format *PolicyExportFormat +} + +func DefaultWorkspaceProductPolicyGetOperationOptions() WorkspaceProductPolicyGetOperationOptions { + return WorkspaceProductPolicyGetOperationOptions{} +} + +func (o WorkspaceProductPolicyGetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceProductPolicyGetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceProductPolicyGetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Format != nil { + out.Append("format", fmt.Sprintf("%v", *o.Format)) + } + return &out +} + +// WorkspaceProductPolicyGet ... +func (c ProductPolicyClient) WorkspaceProductPolicyGet(ctx context.Context, id WorkspaceProductId, options WorkspaceProductPolicyGetOperationOptions) (result WorkspaceProductPolicyGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", 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 PolicyContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productpolicy/method_workspaceproductpolicygetentitytag.go b/resource-manager/apimanagement/2024-05-01/productpolicy/method_workspaceproductpolicygetentitytag.go new file mode 100644 index 00000000000..2b0f1de51e3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productpolicy/method_workspaceproductpolicygetentitytag.go @@ -0,0 +1,47 @@ +package productpolicy + +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 WorkspaceProductPolicyGetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceProductPolicyGetEntityTag ... +func (c ProductPolicyClient) WorkspaceProductPolicyGetEntityTag(ctx context.Context, id WorkspaceProductId) (result WorkspaceProductPolicyGetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: fmt.Sprintf("%s/policies/policy", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productpolicy/method_workspaceproductpolicylistbyproduct.go b/resource-manager/apimanagement/2024-05-01/productpolicy/method_workspaceproductpolicylistbyproduct.go new file mode 100644 index 00000000000..e6db46320f2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productpolicy/method_workspaceproductpolicylistbyproduct.go @@ -0,0 +1,105 @@ +package productpolicy + +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 WorkspaceProductPolicyListByProductOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PolicyContract +} + +type WorkspaceProductPolicyListByProductCompleteResult struct { + LatestHttpResponse *http.Response + Items []PolicyContract +} + +type WorkspaceProductPolicyListByProductCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceProductPolicyListByProductCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceProductPolicyListByProduct ... +func (c ProductPolicyClient) WorkspaceProductPolicyListByProduct(ctx context.Context, id WorkspaceProductId) (result WorkspaceProductPolicyListByProductOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &WorkspaceProductPolicyListByProductCustomPager{}, + Path: fmt.Sprintf("%s/policies", 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 *[]PolicyContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceProductPolicyListByProductComplete retrieves all the results into a single object +func (c ProductPolicyClient) WorkspaceProductPolicyListByProductComplete(ctx context.Context, id WorkspaceProductId) (WorkspaceProductPolicyListByProductCompleteResult, error) { + return c.WorkspaceProductPolicyListByProductCompleteMatchingPredicate(ctx, id, PolicyContractOperationPredicate{}) +} + +// WorkspaceProductPolicyListByProductCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProductPolicyClient) WorkspaceProductPolicyListByProductCompleteMatchingPredicate(ctx context.Context, id WorkspaceProductId, predicate PolicyContractOperationPredicate) (result WorkspaceProductPolicyListByProductCompleteResult, err error) { + items := make([]PolicyContract, 0) + + resp, err := c.WorkspaceProductPolicyListByProduct(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceProductPolicyListByProductCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productpolicy/model_policycontract.go b/resource-manager/apimanagement/2024-05-01/productpolicy/model_policycontract.go new file mode 100644 index 00000000000..63e223631e8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productpolicy/model_policycontract.go @@ -0,0 +1,11 @@ +package productpolicy + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PolicyContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productpolicy/model_policycontractproperties.go b/resource-manager/apimanagement/2024-05-01/productpolicy/model_policycontractproperties.go new file mode 100644 index 00000000000..ac01100ffc1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productpolicy/model_policycontractproperties.go @@ -0,0 +1,9 @@ +package productpolicy + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyContractProperties struct { + Format *PolicyContentFormat `json:"format,omitempty"` + Value string `json:"value"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productpolicy/predicates.go b/resource-manager/apimanagement/2024-05-01/productpolicy/predicates.go new file mode 100644 index 00000000000..d715318d50f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productpolicy/predicates.go @@ -0,0 +1,27 @@ +package productpolicy + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PolicyContractOperationPredicate) Matches(input PolicyContract) 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/apimanagement/2024-05-01/productpolicy/version.go b/resource-manager/apimanagement/2024-05-01/productpolicy/version.go new file mode 100644 index 00000000000..70fbb2c0a93 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productpolicy/version.go @@ -0,0 +1,12 @@ +package productpolicy + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/productpolicy/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/productsbytag/README.md b/resource-manager/apimanagement/2024-05-01/productsbytag/README.md new file mode 100644 index 00000000000..8f9128b5163 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsbytag/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/productsbytag` Documentation + +The `productsbytag` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/productsbytag" +``` + + +### Client Initialization + +```go +client := productsbytag.NewProductsByTagClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ProductsByTagClient.ProductListByTags` + +```go +ctx := context.TODO() +id := productsbytag.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ProductListByTags(ctx, id, productsbytag.DefaultProductListByTagsOperationOptions())` can be used to do batched pagination +items, err := client.ProductListByTagsComplete(ctx, id, productsbytag.DefaultProductListByTagsOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/productsbytag/client.go b/resource-manager/apimanagement/2024-05-01/productsbytag/client.go new file mode 100644 index 00000000000..c87bb5f7b76 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsbytag/client.go @@ -0,0 +1,26 @@ +package productsbytag + +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 ProductsByTagClient struct { + Client *resourcemanager.Client +} + +func NewProductsByTagClientWithBaseURI(sdkApi sdkEnv.Api) (*ProductsByTagClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "productsbytag", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ProductsByTagClient: %+v", err) + } + + return &ProductsByTagClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/productsbytag/constants.go b/resource-manager/apimanagement/2024-05-01/productsbytag/constants.go new file mode 100644 index 00000000000..ed9f254adda --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsbytag/constants.go @@ -0,0 +1,192 @@ +package productsbytag + +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 ApiType string + +const ( + ApiTypeGraphql ApiType = "graphql" + ApiTypeGrpc ApiType = "grpc" + ApiTypeHTTP ApiType = "http" + ApiTypeOdata ApiType = "odata" + ApiTypeSoap ApiType = "soap" + ApiTypeWebsocket ApiType = "websocket" +) + +func PossibleValuesForApiType() []string { + return []string{ + string(ApiTypeGraphql), + string(ApiTypeGrpc), + string(ApiTypeHTTP), + string(ApiTypeOdata), + string(ApiTypeSoap), + string(ApiTypeWebsocket), + } +} + +func (s *ApiType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseApiType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseApiType(input string) (*ApiType, error) { + vals := map[string]ApiType{ + "graphql": ApiTypeGraphql, + "grpc": ApiTypeGrpc, + "http": ApiTypeHTTP, + "odata": ApiTypeOdata, + "soap": ApiTypeSoap, + "websocket": ApiTypeWebsocket, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ApiType(input) + return &out, nil +} + +type BearerTokenSendingMethods string + +const ( + BearerTokenSendingMethodsAuthorizationHeader BearerTokenSendingMethods = "authorizationHeader" + BearerTokenSendingMethodsQuery BearerTokenSendingMethods = "query" +) + +func PossibleValuesForBearerTokenSendingMethods() []string { + return []string{ + string(BearerTokenSendingMethodsAuthorizationHeader), + string(BearerTokenSendingMethodsQuery), + } +} + +func (s *BearerTokenSendingMethods) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBearerTokenSendingMethods(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBearerTokenSendingMethods(input string) (*BearerTokenSendingMethods, error) { + vals := map[string]BearerTokenSendingMethods{ + "authorizationheader": BearerTokenSendingMethodsAuthorizationHeader, + "query": BearerTokenSendingMethodsQuery, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BearerTokenSendingMethods(input) + return &out, nil +} + +type ProductState string + +const ( + ProductStateNotPublished ProductState = "notPublished" + ProductStatePublished ProductState = "published" +) + +func PossibleValuesForProductState() []string { + return []string{ + string(ProductStateNotPublished), + string(ProductStatePublished), + } +} + +func (s *ProductState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProductState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProductState(input string) (*ProductState, error) { + vals := map[string]ProductState{ + "notpublished": ProductStateNotPublished, + "published": ProductStatePublished, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProductState(input) + return &out, nil +} + +type Protocol string + +const ( + ProtocolHTTP Protocol = "http" + ProtocolHTTPS Protocol = "https" + ProtocolWs Protocol = "ws" + ProtocolWss Protocol = "wss" +) + +func PossibleValuesForProtocol() []string { + return []string{ + string(ProtocolHTTP), + string(ProtocolHTTPS), + string(ProtocolWs), + string(ProtocolWss), + } +} + +func (s *Protocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProtocol(input string) (*Protocol, error) { + vals := map[string]Protocol{ + "http": ProtocolHTTP, + "https": ProtocolHTTPS, + "ws": ProtocolWs, + "wss": ProtocolWss, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Protocol(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/productsbytag/id_service.go b/resource-manager/apimanagement/2024-05-01/productsbytag/id_service.go new file mode 100644 index 00000000000..4cf290afcb1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsbytag/id_service.go @@ -0,0 +1,130 @@ +package productsbytag + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/productsbytag/id_service_test.go b/resource-manager/apimanagement/2024-05-01/productsbytag/id_service_test.go new file mode 100644 index 00000000000..27caf6c5bae --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsbytag/id_service_test.go @@ -0,0 +1,282 @@ +package productsbytag + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/productsbytag/method_productlistbytags.go b/resource-manager/apimanagement/2024-05-01/productsbytag/method_productlistbytags.go new file mode 100644 index 00000000000..8cffb9f2edb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsbytag/method_productlistbytags.go @@ -0,0 +1,145 @@ +package productsbytag + +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 ProductListByTagsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TagResourceContract +} + +type ProductListByTagsCompleteResult struct { + LatestHttpResponse *http.Response + Items []TagResourceContract +} + +type ProductListByTagsOperationOptions struct { + Filter *string + IncludeNotTaggedProducts *bool + Skip *int64 + Top *int64 +} + +func DefaultProductListByTagsOperationOptions() ProductListByTagsOperationOptions { + return ProductListByTagsOperationOptions{} +} + +func (o ProductListByTagsOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ProductListByTagsOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ProductListByTagsOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.IncludeNotTaggedProducts != nil { + out.Append("includeNotTaggedProducts", fmt.Sprintf("%v", *o.IncludeNotTaggedProducts)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ProductListByTagsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ProductListByTagsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ProductListByTags ... +func (c ProductsByTagClient) ProductListByTags(ctx context.Context, id ServiceId, options ProductListByTagsOperationOptions) (result ProductListByTagsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ProductListByTagsCustomPager{}, + Path: fmt.Sprintf("%s/productsByTags", 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 *[]TagResourceContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ProductListByTagsComplete retrieves all the results into a single object +func (c ProductsByTagClient) ProductListByTagsComplete(ctx context.Context, id ServiceId, options ProductListByTagsOperationOptions) (ProductListByTagsCompleteResult, error) { + return c.ProductListByTagsCompleteMatchingPredicate(ctx, id, options, TagResourceContractOperationPredicate{}) +} + +// ProductListByTagsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProductsByTagClient) ProductListByTagsCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ProductListByTagsOperationOptions, predicate TagResourceContractOperationPredicate) (result ProductListByTagsCompleteResult, err error) { + items := make([]TagResourceContract, 0) + + resp, err := c.ProductListByTags(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ProductListByTagsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productsbytag/model_apicontactinformation.go b/resource-manager/apimanagement/2024-05-01/productsbytag/model_apicontactinformation.go new file mode 100644 index 00000000000..341ace3b513 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsbytag/model_apicontactinformation.go @@ -0,0 +1,10 @@ +package productsbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiContactInformation struct { + Email *string `json:"email,omitempty"` + Name *string `json:"name,omitempty"` + Url *string `json:"url,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productsbytag/model_apilicenseinformation.go b/resource-manager/apimanagement/2024-05-01/productsbytag/model_apilicenseinformation.go new file mode 100644 index 00000000000..bba1d2352f6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsbytag/model_apilicenseinformation.go @@ -0,0 +1,9 @@ +package productsbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiLicenseInformation struct { + Name *string `json:"name,omitempty"` + Url *string `json:"url,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productsbytag/model_apitagresourcecontractproperties.go b/resource-manager/apimanagement/2024-05-01/productsbytag/model_apitagresourcecontractproperties.go new file mode 100644 index 00000000000..5b6004615a2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsbytag/model_apitagresourcecontractproperties.go @@ -0,0 +1,27 @@ +package productsbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiTagResourceContractProperties struct { + ApiRevision *string `json:"apiRevision,omitempty"` + ApiRevisionDescription *string `json:"apiRevisionDescription,omitempty"` + ApiVersion *string `json:"apiVersion,omitempty"` + ApiVersionDescription *string `json:"apiVersionDescription,omitempty"` + ApiVersionSetId *string `json:"apiVersionSetId,omitempty"` + AuthenticationSettings *AuthenticationSettingsContract `json:"authenticationSettings,omitempty"` + Contact *ApiContactInformation `json:"contact,omitempty"` + Description *string `json:"description,omitempty"` + Id *string `json:"id,omitempty"` + IsCurrent *bool `json:"isCurrent,omitempty"` + IsOnline *bool `json:"isOnline,omitempty"` + License *ApiLicenseInformation `json:"license,omitempty"` + Name *string `json:"name,omitempty"` + Path *string `json:"path,omitempty"` + Protocols *[]Protocol `json:"protocols,omitempty"` + ServiceUrl *string `json:"serviceUrl,omitempty"` + SubscriptionKeyParameterNames *SubscriptionKeyParameterNamesContract `json:"subscriptionKeyParameterNames,omitempty"` + SubscriptionRequired *bool `json:"subscriptionRequired,omitempty"` + TermsOfServiceUrl *string `json:"termsOfServiceUrl,omitempty"` + Type *ApiType `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productsbytag/model_authenticationsettingscontract.go b/resource-manager/apimanagement/2024-05-01/productsbytag/model_authenticationsettingscontract.go new file mode 100644 index 00000000000..9848ab32c75 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsbytag/model_authenticationsettingscontract.go @@ -0,0 +1,11 @@ +package productsbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthenticationSettingsContract struct { + OAuth2 *OAuth2AuthenticationSettingsContract `json:"oAuth2,omitempty"` + OAuth2AuthenticationSettings *[]OAuth2AuthenticationSettingsContract `json:"oAuth2AuthenticationSettings,omitempty"` + Openid *OpenIdAuthenticationSettingsContract `json:"openid,omitempty"` + OpenidAuthenticationSettings *[]OpenIdAuthenticationSettingsContract `json:"openidAuthenticationSettings,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productsbytag/model_oauth2authenticationsettingscontract.go b/resource-manager/apimanagement/2024-05-01/productsbytag/model_oauth2authenticationsettingscontract.go new file mode 100644 index 00000000000..b326ded0849 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsbytag/model_oauth2authenticationsettingscontract.go @@ -0,0 +1,9 @@ +package productsbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OAuth2AuthenticationSettingsContract struct { + AuthorizationServerId *string `json:"authorizationServerId,omitempty"` + Scope *string `json:"scope,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productsbytag/model_openidauthenticationsettingscontract.go b/resource-manager/apimanagement/2024-05-01/productsbytag/model_openidauthenticationsettingscontract.go new file mode 100644 index 00000000000..1c5aeca6805 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsbytag/model_openidauthenticationsettingscontract.go @@ -0,0 +1,9 @@ +package productsbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OpenIdAuthenticationSettingsContract struct { + BearerTokenSendingMethods *[]BearerTokenSendingMethods `json:"bearerTokenSendingMethods,omitempty"` + OpenidProviderId *string `json:"openidProviderId,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productsbytag/model_operationtagresourcecontractproperties.go b/resource-manager/apimanagement/2024-05-01/productsbytag/model_operationtagresourcecontractproperties.go new file mode 100644 index 00000000000..384c31c6691 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsbytag/model_operationtagresourcecontractproperties.go @@ -0,0 +1,15 @@ +package productsbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationTagResourceContractProperties struct { + ApiName *string `json:"apiName,omitempty"` + ApiRevision *string `json:"apiRevision,omitempty"` + ApiVersion *string `json:"apiVersion,omitempty"` + Description *string `json:"description,omitempty"` + Id *string `json:"id,omitempty"` + Method *string `json:"method,omitempty"` + Name *string `json:"name,omitempty"` + UrlTemplate *string `json:"urlTemplate,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productsbytag/model_producttagresourcecontractproperties.go b/resource-manager/apimanagement/2024-05-01/productsbytag/model_producttagresourcecontractproperties.go new file mode 100644 index 00000000000..12e7bcb8de6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsbytag/model_producttagresourcecontractproperties.go @@ -0,0 +1,15 @@ +package productsbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductTagResourceContractProperties struct { + ApprovalRequired *bool `json:"approvalRequired,omitempty"` + Description *string `json:"description,omitempty"` + Id *string `json:"id,omitempty"` + Name string `json:"name"` + State *ProductState `json:"state,omitempty"` + SubscriptionRequired *bool `json:"subscriptionRequired,omitempty"` + SubscriptionsLimit *int64 `json:"subscriptionsLimit,omitempty"` + Terms *string `json:"terms,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productsbytag/model_subscriptionkeyparameternamescontract.go b/resource-manager/apimanagement/2024-05-01/productsbytag/model_subscriptionkeyparameternamescontract.go new file mode 100644 index 00000000000..daea330e92e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsbytag/model_subscriptionkeyparameternamescontract.go @@ -0,0 +1,9 @@ +package productsbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionKeyParameterNamesContract struct { + Header *string `json:"header,omitempty"` + Query *string `json:"query,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productsbytag/model_tagresourcecontract.go b/resource-manager/apimanagement/2024-05-01/productsbytag/model_tagresourcecontract.go new file mode 100644 index 00000000000..ca827e65014 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsbytag/model_tagresourcecontract.go @@ -0,0 +1,11 @@ +package productsbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagResourceContract struct { + Api *ApiTagResourceContractProperties `json:"api,omitempty"` + Operation *OperationTagResourceContractProperties `json:"operation,omitempty"` + Product *ProductTagResourceContractProperties `json:"product,omitempty"` + Tag TagTagResourceContractProperties `json:"tag"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productsbytag/model_tagtagresourcecontractproperties.go b/resource-manager/apimanagement/2024-05-01/productsbytag/model_tagtagresourcecontractproperties.go new file mode 100644 index 00000000000..f8bb6539d73 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsbytag/model_tagtagresourcecontractproperties.go @@ -0,0 +1,9 @@ +package productsbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagTagResourceContractProperties struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productsbytag/predicates.go b/resource-manager/apimanagement/2024-05-01/productsbytag/predicates.go new file mode 100644 index 00000000000..e38ad6c255d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsbytag/predicates.go @@ -0,0 +1,12 @@ +package productsbytag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagResourceContractOperationPredicate struct { +} + +func (p TagResourceContractOperationPredicate) Matches(input TagResourceContract) bool { + + return true +} diff --git a/resource-manager/apimanagement/2024-05-01/productsbytag/version.go b/resource-manager/apimanagement/2024-05-01/productsbytag/version.go new file mode 100644 index 00000000000..16c04a67720 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsbytag/version.go @@ -0,0 +1,12 @@ +package productsbytag + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/productsbytag/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/productsubscription/README.md b/resource-manager/apimanagement/2024-05-01/productsubscription/README.md new file mode 100644 index 00000000000..51f26570381 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsubscription/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/productsubscription` Documentation + +The `productsubscription` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/productsubscription" +``` + + +### Client Initialization + +```go +client := productsubscription.NewProductSubscriptionClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ProductSubscriptionClient.List` + +```go +ctx := context.TODO() +id := productsubscription.NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + +// alternatively `client.List(ctx, id, productsubscription.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, productsubscription.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/productsubscription/client.go b/resource-manager/apimanagement/2024-05-01/productsubscription/client.go new file mode 100644 index 00000000000..a54f7218145 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsubscription/client.go @@ -0,0 +1,26 @@ +package productsubscription + +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 ProductSubscriptionClient struct { + Client *resourcemanager.Client +} + +func NewProductSubscriptionClientWithBaseURI(sdkApi sdkEnv.Api) (*ProductSubscriptionClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "productsubscription", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ProductSubscriptionClient: %+v", err) + } + + return &ProductSubscriptionClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/productsubscription/constants.go b/resource-manager/apimanagement/2024-05-01/productsubscription/constants.go new file mode 100644 index 00000000000..b701ce04fea --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsubscription/constants.go @@ -0,0 +1,63 @@ +package productsubscription + +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 SubscriptionState string + +const ( + SubscriptionStateActive SubscriptionState = "active" + SubscriptionStateCancelled SubscriptionState = "cancelled" + SubscriptionStateExpired SubscriptionState = "expired" + SubscriptionStateRejected SubscriptionState = "rejected" + SubscriptionStateSubmitted SubscriptionState = "submitted" + SubscriptionStateSuspended SubscriptionState = "suspended" +) + +func PossibleValuesForSubscriptionState() []string { + return []string{ + string(SubscriptionStateActive), + string(SubscriptionStateCancelled), + string(SubscriptionStateExpired), + string(SubscriptionStateRejected), + string(SubscriptionStateSubmitted), + string(SubscriptionStateSuspended), + } +} + +func (s *SubscriptionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSubscriptionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSubscriptionState(input string) (*SubscriptionState, error) { + vals := map[string]SubscriptionState{ + "active": SubscriptionStateActive, + "cancelled": SubscriptionStateCancelled, + "expired": SubscriptionStateExpired, + "rejected": SubscriptionStateRejected, + "submitted": SubscriptionStateSubmitted, + "suspended": SubscriptionStateSuspended, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SubscriptionState(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/productsubscription/id_product.go b/resource-manager/apimanagement/2024-05-01/productsubscription/id_product.go new file mode 100644 index 00000000000..96929544e81 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsubscription/id_product.go @@ -0,0 +1,139 @@ +package productsubscription + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProductId{}) +} + +var _ resourceids.ResourceId = &ProductId{} + +// ProductId is a struct representing the Resource ID for a Product +type ProductId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ProductId string +} + +// NewProductID returns a new ProductId struct +func NewProductID(subscriptionId string, resourceGroupName string, serviceName string, productId string) ProductId { + return ProductId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ProductId: productId, + } +} + +// ParseProductID parses 'input' into a ProductId +func ParseProductID(input string) (*ProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProductIDInsensitively parses 'input' case-insensitively into a ProductId +// note: this method should only be used for API response data and not user input +func ParseProductIDInsensitively(input string) (*ProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProductId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ProductId, ok = input.Parsed["productId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "productId", input) + } + + return nil +} + +// ValidateProductID checks that 'input' can be parsed as a Product ID +func ValidateProductID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseProductID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Product ID +func (id ProductId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/products/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ProductId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Product ID +func (id ProductId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticProducts", "products", "products"), + resourceids.UserSpecifiedSegment("productId", "productIdValue"), + } +} + +// String returns a human-readable description of this Product ID +func (id ProductId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Product: %q", id.ProductId), + } + return fmt.Sprintf("Product (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/productsubscription/id_product_test.go b/resource-manager/apimanagement/2024-05-01/productsubscription/id_product_test.go new file mode 100644 index 00000000000..6021059e370 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsubscription/id_product_test.go @@ -0,0 +1,327 @@ +package productsubscription + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ProductId{} + +func TestNewProductID(t *testing.T) { + id := NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ProductId != "productIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProductId'", id.ProductId, "productIdValue") + } +} + +func TestFormatProductID(t *testing.T) { + actual := NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProductID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestParseProductIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ProductId: "pRoDuCtIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestSegmentsForProductId(t *testing.T) { + segments := ProductId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProductId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/productsubscription/method_list.go b/resource-manager/apimanagement/2024-05-01/productsubscription/method_list.go new file mode 100644 index 00000000000..c71c7ba8260 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsubscription/method_list.go @@ -0,0 +1,141 @@ +package productsubscription + +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 *[]SubscriptionContract +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []SubscriptionContract +} + +type ListOperationOptions struct { + Filter *string + Skip *int64 + 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.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ProductSubscriptionClient) List(ctx context.Context, id ProductId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/subscriptions", 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 *[]SubscriptionContract `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 ProductSubscriptionClient) ListComplete(ctx context.Context, id ProductId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, SubscriptionContractOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProductSubscriptionClient) ListCompleteMatchingPredicate(ctx context.Context, id ProductId, options ListOperationOptions, predicate SubscriptionContractOperationPredicate) (result ListCompleteResult, err error) { + items := make([]SubscriptionContract, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productsubscription/model_subscriptioncontract.go b/resource-manager/apimanagement/2024-05-01/productsubscription/model_subscriptioncontract.go new file mode 100644 index 00000000000..ae2d8bf5939 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsubscription/model_subscriptioncontract.go @@ -0,0 +1,11 @@ +package productsubscription + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SubscriptionContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productsubscription/model_subscriptioncontractproperties.go b/resource-manager/apimanagement/2024-05-01/productsubscription/model_subscriptioncontractproperties.go new file mode 100644 index 00000000000..47184224572 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsubscription/model_subscriptioncontractproperties.go @@ -0,0 +1,86 @@ +package productsubscription + +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 SubscriptionContractProperties struct { + AllowTracing *bool `json:"allowTracing,omitempty"` + CreatedDate *string `json:"createdDate,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + EndDate *string `json:"endDate,omitempty"` + ExpirationDate *string `json:"expirationDate,omitempty"` + NotificationDate *string `json:"notificationDate,omitempty"` + OwnerId *string `json:"ownerId,omitempty"` + PrimaryKey *string `json:"primaryKey,omitempty"` + Scope string `json:"scope"` + SecondaryKey *string `json:"secondaryKey,omitempty"` + StartDate *string `json:"startDate,omitempty"` + State SubscriptionState `json:"state"` + StateComment *string `json:"stateComment,omitempty"` +} + +func (o *SubscriptionContractProperties) GetCreatedDateAsTime() (*time.Time, error) { + if o.CreatedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SubscriptionContractProperties) SetCreatedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedDate = &formatted +} + +func (o *SubscriptionContractProperties) GetEndDateAsTime() (*time.Time, error) { + if o.EndDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SubscriptionContractProperties) SetEndDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndDate = &formatted +} + +func (o *SubscriptionContractProperties) GetExpirationDateAsTime() (*time.Time, error) { + if o.ExpirationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpirationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SubscriptionContractProperties) SetExpirationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpirationDate = &formatted +} + +func (o *SubscriptionContractProperties) GetNotificationDateAsTime() (*time.Time, error) { + if o.NotificationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.NotificationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SubscriptionContractProperties) SetNotificationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.NotificationDate = &formatted +} + +func (o *SubscriptionContractProperties) GetStartDateAsTime() (*time.Time, error) { + if o.StartDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SubscriptionContractProperties) SetStartDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartDate = &formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/productsubscription/predicates.go b/resource-manager/apimanagement/2024-05-01/productsubscription/predicates.go new file mode 100644 index 00000000000..66c5b3fd316 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsubscription/predicates.go @@ -0,0 +1,27 @@ +package productsubscription + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SubscriptionContractOperationPredicate) Matches(input SubscriptionContract) 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/apimanagement/2024-05-01/productsubscription/version.go b/resource-manager/apimanagement/2024-05-01/productsubscription/version.go new file mode 100644 index 00000000000..8186cd85f7b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productsubscription/version.go @@ -0,0 +1,12 @@ +package productsubscription + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/productsubscription/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/producttag/README.md b/resource-manager/apimanagement/2024-05-01/producttag/README.md new file mode 100644 index 00000000000..a56e6bbcbf7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/producttag/README.md @@ -0,0 +1,101 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/producttag` Documentation + +The `producttag` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/producttag" +``` + + +### Client Initialization + +```go +client := producttag.NewProductTagClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ProductTagClient.TagAssignToProduct` + +```go +ctx := context.TODO() +id := producttag.NewProductTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "tagIdValue") + +read, err := client.TagAssignToProduct(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductTagClient.TagDetachFromProduct` + +```go +ctx := context.TODO() +id := producttag.NewProductTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "tagIdValue") + +read, err := client.TagDetachFromProduct(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductTagClient.TagGetByProduct` + +```go +ctx := context.TODO() +id := producttag.NewProductTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "tagIdValue") + +read, err := client.TagGetByProduct(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductTagClient.TagGetEntityStateByProduct` + +```go +ctx := context.TODO() +id := producttag.NewProductTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "tagIdValue") + +read, err := client.TagGetEntityStateByProduct(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductTagClient.TagListByProduct` + +```go +ctx := context.TODO() +id := producttag.NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + +// alternatively `client.TagListByProduct(ctx, id, producttag.DefaultTagListByProductOperationOptions())` can be used to do batched pagination +items, err := client.TagListByProductComplete(ctx, id, producttag.DefaultTagListByProductOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/producttag/client.go b/resource-manager/apimanagement/2024-05-01/producttag/client.go new file mode 100644 index 00000000000..720b81ec2d8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/producttag/client.go @@ -0,0 +1,26 @@ +package producttag + +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 ProductTagClient struct { + Client *resourcemanager.Client +} + +func NewProductTagClientWithBaseURI(sdkApi sdkEnv.Api) (*ProductTagClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "producttag", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ProductTagClient: %+v", err) + } + + return &ProductTagClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/producttag/id_product.go b/resource-manager/apimanagement/2024-05-01/producttag/id_product.go new file mode 100644 index 00000000000..b7000f83b74 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/producttag/id_product.go @@ -0,0 +1,139 @@ +package producttag + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProductId{}) +} + +var _ resourceids.ResourceId = &ProductId{} + +// ProductId is a struct representing the Resource ID for a Product +type ProductId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ProductId string +} + +// NewProductID returns a new ProductId struct +func NewProductID(subscriptionId string, resourceGroupName string, serviceName string, productId string) ProductId { + return ProductId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ProductId: productId, + } +} + +// ParseProductID parses 'input' into a ProductId +func ParseProductID(input string) (*ProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProductIDInsensitively parses 'input' case-insensitively into a ProductId +// note: this method should only be used for API response data and not user input +func ParseProductIDInsensitively(input string) (*ProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProductId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ProductId, ok = input.Parsed["productId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "productId", input) + } + + return nil +} + +// ValidateProductID checks that 'input' can be parsed as a Product ID +func ValidateProductID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseProductID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Product ID +func (id ProductId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/products/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ProductId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Product ID +func (id ProductId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticProducts", "products", "products"), + resourceids.UserSpecifiedSegment("productId", "productIdValue"), + } +} + +// String returns a human-readable description of this Product ID +func (id ProductId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Product: %q", id.ProductId), + } + return fmt.Sprintf("Product (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/producttag/id_product_test.go b/resource-manager/apimanagement/2024-05-01/producttag/id_product_test.go new file mode 100644 index 00000000000..f7459c1f331 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/producttag/id_product_test.go @@ -0,0 +1,327 @@ +package producttag + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ProductId{} + +func TestNewProductID(t *testing.T) { + id := NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ProductId != "productIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProductId'", id.ProductId, "productIdValue") + } +} + +func TestFormatProductID(t *testing.T) { + actual := NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProductID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestParseProductIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ProductId: "pRoDuCtIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestSegmentsForProductId(t *testing.T) { + segments := ProductId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProductId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/producttag/id_producttag.go b/resource-manager/apimanagement/2024-05-01/producttag/id_producttag.go new file mode 100644 index 00000000000..d1f16bd1686 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/producttag/id_producttag.go @@ -0,0 +1,148 @@ +package producttag + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProductTagId{}) +} + +var _ resourceids.ResourceId = &ProductTagId{} + +// ProductTagId is a struct representing the Resource ID for a Product Tag +type ProductTagId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ProductId string + TagId string +} + +// NewProductTagID returns a new ProductTagId struct +func NewProductTagID(subscriptionId string, resourceGroupName string, serviceName string, productId string, tagId string) ProductTagId { + return ProductTagId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ProductId: productId, + TagId: tagId, + } +} + +// ParseProductTagID parses 'input' into a ProductTagId +func ParseProductTagID(input string) (*ProductTagId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductTagId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductTagId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProductTagIDInsensitively parses 'input' case-insensitively into a ProductTagId +// note: this method should only be used for API response data and not user input +func ParseProductTagIDInsensitively(input string) (*ProductTagId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductTagId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductTagId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProductTagId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ProductId, ok = input.Parsed["productId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "productId", input) + } + + if id.TagId, ok = input.Parsed["tagId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagId", input) + } + + return nil +} + +// ValidateProductTagID checks that 'input' can be parsed as a Product Tag ID +func ValidateProductTagID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseProductTagID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Product Tag ID +func (id ProductTagId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/products/%s/tags/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ProductId, id.TagId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Product Tag ID +func (id ProductTagId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticProducts", "products", "products"), + resourceids.UserSpecifiedSegment("productId", "productIdValue"), + resourceids.StaticSegment("staticTags", "tags", "tags"), + resourceids.UserSpecifiedSegment("tagId", "tagIdValue"), + } +} + +// String returns a human-readable description of this Product Tag ID +func (id ProductTagId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Product: %q", id.ProductId), + fmt.Sprintf("Tag: %q", id.TagId), + } + return fmt.Sprintf("Product Tag (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/producttag/id_producttag_test.go b/resource-manager/apimanagement/2024-05-01/producttag/id_producttag_test.go new file mode 100644 index 00000000000..0ab85c72540 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/producttag/id_producttag_test.go @@ -0,0 +1,372 @@ +package producttag + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ProductTagId{} + +func TestNewProductTagID(t *testing.T) { + id := NewProductTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "tagIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ProductId != "productIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProductId'", id.ProductId, "productIdValue") + } + + if id.TagId != "tagIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'TagId'", id.TagId, "tagIdValue") + } +} + +func TestFormatProductTagID(t *testing.T) { + actual := NewProductTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue", "tagIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/tags/tagIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProductTagID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductTagId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/tags", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/tags/tagIdValue", + Expected: &ProductTagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + TagId: "tagIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/tags/tagIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductTagID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + } +} + +func TestParseProductTagIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductTagId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/tags", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/tAgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/tags/tagIdValue", + Expected: &ProductTagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + TagId: "tagIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/tags/tagIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/tAgS/tAgIdVaLuE", + Expected: &ProductTagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ProductId: "pRoDuCtIdVaLuE", + TagId: "tAgIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/tAgS/tAgIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductTagIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + } +} + +func TestSegmentsForProductTagId(t *testing.T) { + segments := ProductTagId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProductTagId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/producttag/method_tagassigntoproduct.go b/resource-manager/apimanagement/2024-05-01/producttag/method_tagassigntoproduct.go new file mode 100644 index 00000000000..87bb16caf5e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/producttag/method_tagassigntoproduct.go @@ -0,0 +1,55 @@ +package producttag + +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 TagAssignToProductOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TagContract +} + +// TagAssignToProduct ... +func (c ProductTagClient) TagAssignToProduct(ctx context.Context, id ProductTagId) (result TagAssignToProductOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model TagContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/producttag/method_tagdetachfromproduct.go b/resource-manager/apimanagement/2024-05-01/producttag/method_tagdetachfromproduct.go new file mode 100644 index 00000000000..9564ceb67e1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/producttag/method_tagdetachfromproduct.go @@ -0,0 +1,47 @@ +package producttag + +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 TagDetachFromProductOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// TagDetachFromProduct ... +func (c ProductTagClient) TagDetachFromProduct(ctx context.Context, id ProductTagId) (result TagDetachFromProductOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/producttag/method_taggetbyproduct.go b/resource-manager/apimanagement/2024-05-01/producttag/method_taggetbyproduct.go new file mode 100644 index 00000000000..1e5ed741301 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/producttag/method_taggetbyproduct.go @@ -0,0 +1,54 @@ +package producttag + +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 TagGetByProductOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TagContract +} + +// TagGetByProduct ... +func (c ProductTagClient) TagGetByProduct(ctx context.Context, id ProductTagId) (result TagGetByProductOperationResponse, 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 TagContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/producttag/method_taggetentitystatebyproduct.go b/resource-manager/apimanagement/2024-05-01/producttag/method_taggetentitystatebyproduct.go new file mode 100644 index 00000000000..8f023009406 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/producttag/method_taggetentitystatebyproduct.go @@ -0,0 +1,46 @@ +package producttag + +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 TagGetEntityStateByProductOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// TagGetEntityStateByProduct ... +func (c ProductTagClient) TagGetEntityStateByProduct(ctx context.Context, id ProductTagId) (result TagGetEntityStateByProductOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/producttag/method_taglistbyproduct.go b/resource-manager/apimanagement/2024-05-01/producttag/method_taglistbyproduct.go new file mode 100644 index 00000000000..4e0721b94fc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/producttag/method_taglistbyproduct.go @@ -0,0 +1,141 @@ +package producttag + +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 TagListByProductOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TagContract +} + +type TagListByProductCompleteResult struct { + LatestHttpResponse *http.Response + Items []TagContract +} + +type TagListByProductOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultTagListByProductOperationOptions() TagListByProductOperationOptions { + return TagListByProductOperationOptions{} +} + +func (o TagListByProductOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o TagListByProductOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o TagListByProductOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type TagListByProductCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *TagListByProductCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// TagListByProduct ... +func (c ProductTagClient) TagListByProduct(ctx context.Context, id ProductId, options TagListByProductOperationOptions) (result TagListByProductOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &TagListByProductCustomPager{}, + Path: fmt.Sprintf("%s/tags", 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 *[]TagContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// TagListByProductComplete retrieves all the results into a single object +func (c ProductTagClient) TagListByProductComplete(ctx context.Context, id ProductId, options TagListByProductOperationOptions) (TagListByProductCompleteResult, error) { + return c.TagListByProductCompleteMatchingPredicate(ctx, id, options, TagContractOperationPredicate{}) +} + +// TagListByProductCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProductTagClient) TagListByProductCompleteMatchingPredicate(ctx context.Context, id ProductId, options TagListByProductOperationOptions, predicate TagContractOperationPredicate) (result TagListByProductCompleteResult, err error) { + items := make([]TagContract, 0) + + resp, err := c.TagListByProduct(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = TagListByProductCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/producttag/model_tagcontract.go b/resource-manager/apimanagement/2024-05-01/producttag/model_tagcontract.go new file mode 100644 index 00000000000..8dbd2dfbb6f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/producttag/model_tagcontract.go @@ -0,0 +1,11 @@ +package producttag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *TagContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/producttag/model_tagcontractproperties.go b/resource-manager/apimanagement/2024-05-01/producttag/model_tagcontractproperties.go new file mode 100644 index 00000000000..02f03d01fa3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/producttag/model_tagcontractproperties.go @@ -0,0 +1,8 @@ +package producttag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagContractProperties struct { + DisplayName string `json:"displayName"` +} diff --git a/resource-manager/apimanagement/2024-05-01/producttag/predicates.go b/resource-manager/apimanagement/2024-05-01/producttag/predicates.go new file mode 100644 index 00000000000..cc40ebaa06a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/producttag/predicates.go @@ -0,0 +1,27 @@ +package producttag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p TagContractOperationPredicate) Matches(input TagContract) 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/apimanagement/2024-05-01/producttag/version.go b/resource-manager/apimanagement/2024-05-01/producttag/version.go new file mode 100644 index 00000000000..ff42dfc36fb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/producttag/version.go @@ -0,0 +1,12 @@ +package producttag + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/producttag/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/productwiki/README.md b/resource-manager/apimanagement/2024-05-01/productwiki/README.md new file mode 100644 index 00000000000..0fc5e45aff7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productwiki/README.md @@ -0,0 +1,127 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/productwiki` Documentation + +The `productwiki` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/productwiki" +``` + + +### Client Initialization + +```go +client := productwiki.NewProductWikiClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ProductWikiClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := productwiki.NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + +payload := productwiki.WikiContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, productwiki.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductWikiClient.Delete` + +```go +ctx := context.TODO() +id := productwiki.NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + +read, err := client.Delete(ctx, id, productwiki.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductWikiClient.Get` + +```go +ctx := context.TODO() +id := productwiki.NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + +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: `ProductWikiClient.GetEntityTag` + +```go +ctx := context.TODO() +id := productwiki.NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProductWikiClient.List` + +```go +ctx := context.TODO() +id := productwiki.NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + +// alternatively `client.List(ctx, id, productwiki.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, productwiki.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ProductWikiClient.Update` + +```go +ctx := context.TODO() +id := productwiki.NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + +payload := productwiki.WikiUpdateContract{ + // ... +} + + +read, err := client.Update(ctx, id, payload, productwiki.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/productwiki/client.go b/resource-manager/apimanagement/2024-05-01/productwiki/client.go new file mode 100644 index 00000000000..927c4e2a5e8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productwiki/client.go @@ -0,0 +1,26 @@ +package productwiki + +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 ProductWikiClient struct { + Client *resourcemanager.Client +} + +func NewProductWikiClientWithBaseURI(sdkApi sdkEnv.Api) (*ProductWikiClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "productwiki", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ProductWikiClient: %+v", err) + } + + return &ProductWikiClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/productwiki/id_product.go b/resource-manager/apimanagement/2024-05-01/productwiki/id_product.go new file mode 100644 index 00000000000..55d2312cec7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productwiki/id_product.go @@ -0,0 +1,139 @@ +package productwiki + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProductId{}) +} + +var _ resourceids.ResourceId = &ProductId{} + +// ProductId is a struct representing the Resource ID for a Product +type ProductId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + ProductId string +} + +// NewProductID returns a new ProductId struct +func NewProductID(subscriptionId string, resourceGroupName string, serviceName string, productId string) ProductId { + return ProductId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + ProductId: productId, + } +} + +// ParseProductID parses 'input' into a ProductId +func ParseProductID(input string) (*ProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProductIDInsensitively parses 'input' case-insensitively into a ProductId +// note: this method should only be used for API response data and not user input +func ParseProductIDInsensitively(input string) (*ProductId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProductId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.ProductId, ok = input.Parsed["productId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "productId", input) + } + + return nil +} + +// ValidateProductID checks that 'input' can be parsed as a Product ID +func ValidateProductID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseProductID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Product ID +func (id ProductId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/products/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ProductId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Product ID +func (id ProductId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticProducts", "products", "products"), + resourceids.UserSpecifiedSegment("productId", "productIdValue"), + } +} + +// String returns a human-readable description of this Product ID +func (id ProductId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Product: %q", id.ProductId), + } + return fmt.Sprintf("Product (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/productwiki/id_product_test.go b/resource-manager/apimanagement/2024-05-01/productwiki/id_product_test.go new file mode 100644 index 00000000000..a5337b0cb0e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productwiki/id_product_test.go @@ -0,0 +1,327 @@ +package productwiki + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ProductId{} + +func TestNewProductID(t *testing.T) { + id := NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.ProductId != "productIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProductId'", id.ProductId, "productIdValue") + } +} + +func TestFormatProductID(t *testing.T) { + actual := NewProductID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "productIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProductID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestParseProductIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + ProductId: "productIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/products/productIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE", + Expected: &ProductId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + ProductId: "pRoDuCtIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/pRoDuCtS/pRoDuCtIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.ProductId != v.Expected.ProductId { + t.Fatalf("Expected %q but got %q for ProductId", v.Expected.ProductId, actual.ProductId) + } + + } +} + +func TestSegmentsForProductId(t *testing.T) { + segments := ProductId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProductId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/productwiki/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/productwiki/method_createorupdate.go new file mode 100644 index 00000000000..f794fc61c8a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productwiki/method_createorupdate.go @@ -0,0 +1,88 @@ +package productwiki + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WikiContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c ProductWikiClient) CreateOrUpdate(ctx context.Context, id ProductId, input WikiContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + Path: fmt.Sprintf("%s/wikis/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 + } + + var model WikiContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productwiki/method_delete.go b/resource-manager/apimanagement/2024-05-01/productwiki/method_delete.go new file mode 100644 index 00000000000..0ccc22248a0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productwiki/method_delete.go @@ -0,0 +1,76 @@ +package productwiki + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c ProductWikiClient) Delete(ctx context.Context, id ProductId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: fmt.Sprintf("%s/wikis/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 + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productwiki/method_get.go b/resource-manager/apimanagement/2024-05-01/productwiki/method_get.go new file mode 100644 index 00000000000..503a2a49ab6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productwiki/method_get.go @@ -0,0 +1,55 @@ +package productwiki + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WikiContract +} + +// Get ... +func (c ProductWikiClient) Get(ctx context.Context, id ProductId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/wikis/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 WikiContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productwiki/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/productwiki/method_getentitytag.go new file mode 100644 index 00000000000..ddec183a011 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productwiki/method_getentitytag.go @@ -0,0 +1,47 @@ +package productwiki + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c ProductWikiClient) GetEntityTag(ctx context.Context, id ProductId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: fmt.Sprintf("%s/wikis/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 + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productwiki/method_list.go b/resource-manager/apimanagement/2024-05-01/productwiki/method_list.go new file mode 100644 index 00000000000..db26ef5879d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productwiki/method_list.go @@ -0,0 +1,141 @@ +package productwiki + +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 *[]WikiContract +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []WikiContract +} + +type ListOperationOptions struct { + Filter *string + Skip *int64 + 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.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ProductWikiClient) List(ctx context.Context, id ProductId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/wikis", 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 *[]WikiContract `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 ProductWikiClient) ListComplete(ctx context.Context, id ProductId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, WikiContractOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProductWikiClient) ListCompleteMatchingPredicate(ctx context.Context, id ProductId, options ListOperationOptions, predicate WikiContractOperationPredicate) (result ListCompleteResult, err error) { + items := make([]WikiContract, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productwiki/method_update.go b/resource-manager/apimanagement/2024-05-01/productwiki/method_update.go new file mode 100644 index 00000000000..551aa6aab7a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productwiki/method_update.go @@ -0,0 +1,87 @@ +package productwiki + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WikiContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c ProductWikiClient) Update(ctx context.Context, id ProductId, input WikiUpdateContract, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + Path: fmt.Sprintf("%s/wikis/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 + } + + var model WikiContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/productwiki/model_wikicontract.go b/resource-manager/apimanagement/2024-05-01/productwiki/model_wikicontract.go new file mode 100644 index 00000000000..bc387a202a7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productwiki/model_wikicontract.go @@ -0,0 +1,11 @@ +package productwiki + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WikiContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *WikiContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productwiki/model_wikicontractproperties.go b/resource-manager/apimanagement/2024-05-01/productwiki/model_wikicontractproperties.go new file mode 100644 index 00000000000..804d9af85fb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productwiki/model_wikicontractproperties.go @@ -0,0 +1,8 @@ +package productwiki + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WikiContractProperties struct { + Documents *[]WikiDocumentationContract `json:"documents,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productwiki/model_wikidocumentationcontract.go b/resource-manager/apimanagement/2024-05-01/productwiki/model_wikidocumentationcontract.go new file mode 100644 index 00000000000..4ef8ef53561 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productwiki/model_wikidocumentationcontract.go @@ -0,0 +1,8 @@ +package productwiki + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WikiDocumentationContract struct { + DocumentationId *string `json:"documentationId,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productwiki/model_wikiupdatecontract.go b/resource-manager/apimanagement/2024-05-01/productwiki/model_wikiupdatecontract.go new file mode 100644 index 00000000000..1dcd14558ae --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productwiki/model_wikiupdatecontract.go @@ -0,0 +1,8 @@ +package productwiki + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WikiUpdateContract struct { + Properties *WikiContractProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/productwiki/predicates.go b/resource-manager/apimanagement/2024-05-01/productwiki/predicates.go new file mode 100644 index 00000000000..e91edaf5c86 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productwiki/predicates.go @@ -0,0 +1,27 @@ +package productwiki + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WikiContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p WikiContractOperationPredicate) Matches(input WikiContract) 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/apimanagement/2024-05-01/productwiki/version.go b/resource-manager/apimanagement/2024-05-01/productwiki/version.go new file mode 100644 index 00000000000..34f02bc39a3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/productwiki/version.go @@ -0,0 +1,12 @@ +package productwiki + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/productwiki/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/README.md b/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/README.md new file mode 100644 index 00000000000..285494e223a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/README.md @@ -0,0 +1,58 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/quotabycounterkeys` Documentation + +The `quotabycounterkeys` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/quotabycounterkeys" +``` + + +### Client Initialization + +```go +client := quotabycounterkeys.NewQuotaByCounterKeysClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `QuotaByCounterKeysClient.ListByService` + +```go +ctx := context.TODO() +id := quotabycounterkeys.NewQuotaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "quotaCounterKeyValue") + +// alternatively `client.ListByService(ctx, id)` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `QuotaByCounterKeysClient.Update` + +```go +ctx := context.TODO() +id := quotabycounterkeys.NewQuotaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "quotaCounterKeyValue") + +payload := quotabycounterkeys.QuotaCounterValueUpdateContract{ + // ... +} + + +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/apimanagement/2024-05-01/quotabycounterkeys/client.go b/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/client.go new file mode 100644 index 00000000000..bd6e9581304 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/client.go @@ -0,0 +1,26 @@ +package quotabycounterkeys + +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 QuotaByCounterKeysClient struct { + Client *resourcemanager.Client +} + +func NewQuotaByCounterKeysClientWithBaseURI(sdkApi sdkEnv.Api) (*QuotaByCounterKeysClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "quotabycounterkeys", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating QuotaByCounterKeysClient: %+v", err) + } + + return &QuotaByCounterKeysClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/id_quota.go b/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/id_quota.go new file mode 100644 index 00000000000..11bd5535194 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/id_quota.go @@ -0,0 +1,139 @@ +package quotabycounterkeys + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&QuotaId{}) +} + +var _ resourceids.ResourceId = &QuotaId{} + +// QuotaId is a struct representing the Resource ID for a Quota +type QuotaId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + QuotaCounterKey string +} + +// NewQuotaID returns a new QuotaId struct +func NewQuotaID(subscriptionId string, resourceGroupName string, serviceName string, quotaCounterKey string) QuotaId { + return QuotaId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + QuotaCounterKey: quotaCounterKey, + } +} + +// ParseQuotaID parses 'input' into a QuotaId +func ParseQuotaID(input string) (*QuotaId, error) { + parser := resourceids.NewParserFromResourceIdType(&QuotaId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := QuotaId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseQuotaIDInsensitively parses 'input' case-insensitively into a QuotaId +// note: this method should only be used for API response data and not user input +func ParseQuotaIDInsensitively(input string) (*QuotaId, error) { + parser := resourceids.NewParserFromResourceIdType(&QuotaId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := QuotaId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *QuotaId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.QuotaCounterKey, ok = input.Parsed["quotaCounterKey"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "quotaCounterKey", input) + } + + return nil +} + +// ValidateQuotaID checks that 'input' can be parsed as a Quota ID +func ValidateQuotaID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseQuotaID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Quota ID +func (id QuotaId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/quotas/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.QuotaCounterKey) +} + +// Segments returns a slice of Resource ID Segments which comprise this Quota ID +func (id QuotaId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticQuotas", "quotas", "quotas"), + resourceids.UserSpecifiedSegment("quotaCounterKey", "quotaCounterKeyValue"), + } +} + +// String returns a human-readable description of this Quota ID +func (id QuotaId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Quota Counter Key: %q", id.QuotaCounterKey), + } + return fmt.Sprintf("Quota (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/id_quota_test.go b/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/id_quota_test.go new file mode 100644 index 00000000000..adc7dafad58 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/id_quota_test.go @@ -0,0 +1,327 @@ +package quotabycounterkeys + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &QuotaId{} + +func TestNewQuotaID(t *testing.T) { + id := NewQuotaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "quotaCounterKeyValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.QuotaCounterKey != "quotaCounterKeyValue" { + t.Fatalf("Expected %q but got %q for Segment 'QuotaCounterKey'", id.QuotaCounterKey, "quotaCounterKeyValue") + } +} + +func TestFormatQuotaID(t *testing.T) { + actual := NewQuotaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "quotaCounterKeyValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/quotas/quotaCounterKeyValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseQuotaID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *QuotaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/quotas", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/quotas/quotaCounterKeyValue", + Expected: &QuotaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + QuotaCounterKey: "quotaCounterKeyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/quotas/quotaCounterKeyValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseQuotaID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.QuotaCounterKey != v.Expected.QuotaCounterKey { + t.Fatalf("Expected %q but got %q for QuotaCounterKey", v.Expected.QuotaCounterKey, actual.QuotaCounterKey) + } + + } +} + +func TestParseQuotaIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *QuotaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/quotas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/qUoTaS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/quotas/quotaCounterKeyValue", + Expected: &QuotaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + QuotaCounterKey: "quotaCounterKeyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/quotas/quotaCounterKeyValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/qUoTaS/qUoTaCoUnTeRkEyVaLuE", + Expected: &QuotaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + QuotaCounterKey: "qUoTaCoUnTeRkEyVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/qUoTaS/qUoTaCoUnTeRkEyVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseQuotaIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.QuotaCounterKey != v.Expected.QuotaCounterKey { + t.Fatalf("Expected %q but got %q for QuotaCounterKey", v.Expected.QuotaCounterKey, actual.QuotaCounterKey) + } + + } +} + +func TestSegmentsForQuotaId(t *testing.T) { + segments := QuotaId{}.Segments() + if len(segments) == 0 { + t.Fatalf("QuotaId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/method_listbyservice.go new file mode 100644 index 00000000000..bcc302ce38e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/method_listbyservice.go @@ -0,0 +1,105 @@ +package quotabycounterkeys + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]QuotaCounterContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []QuotaCounterContract +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c QuotaByCounterKeysClient) ListByService(ctx context.Context, id QuotaId) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServiceCustomPager{}, + Path: 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 *[]QuotaCounterContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c QuotaByCounterKeysClient) ListByServiceComplete(ctx context.Context, id QuotaId) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, QuotaCounterContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c QuotaByCounterKeysClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id QuotaId, predicate QuotaCounterContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]QuotaCounterContract, 0) + + resp, err := c.ListByService(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/method_update.go b/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/method_update.go new file mode 100644 index 00000000000..44f72d4b26b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/method_update.go @@ -0,0 +1,58 @@ +package quotabycounterkeys + +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 *QuotaCounterCollection +} + +// Update ... +func (c QuotaByCounterKeysClient) Update(ctx context.Context, id QuotaId, input QuotaCounterValueUpdateContract) (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 + } + + var model QuotaCounterCollection + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/model_quotacountercollection.go b/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/model_quotacountercollection.go new file mode 100644 index 00000000000..1dbfce4b143 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/model_quotacountercollection.go @@ -0,0 +1,10 @@ +package quotabycounterkeys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaCounterCollection struct { + Count *int64 `json:"count,omitempty"` + NextLink *string `json:"nextLink,omitempty"` + Value *[]QuotaCounterContract `json:"value,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/model_quotacountercontract.go b/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/model_quotacountercontract.go new file mode 100644 index 00000000000..a8e2502d54f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/model_quotacountercontract.go @@ -0,0 +1,36 @@ +package quotabycounterkeys + +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 QuotaCounterContract struct { + CounterKey string `json:"counterKey"` + PeriodEndTime string `json:"periodEndTime"` + PeriodKey string `json:"periodKey"` + PeriodStartTime string `json:"periodStartTime"` + Value *QuotaCounterValueContractProperties `json:"value,omitempty"` +} + +func (o *QuotaCounterContract) GetPeriodEndTimeAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.PeriodEndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *QuotaCounterContract) SetPeriodEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.PeriodEndTime = formatted +} + +func (o *QuotaCounterContract) GetPeriodStartTimeAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.PeriodStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *QuotaCounterContract) SetPeriodStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.PeriodStartTime = formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/model_quotacountervaluecontractproperties.go b/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/model_quotacountervaluecontractproperties.go new file mode 100644 index 00000000000..7b69c107694 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/model_quotacountervaluecontractproperties.go @@ -0,0 +1,9 @@ +package quotabycounterkeys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaCounterValueContractProperties struct { + CallsCount *int64 `json:"callsCount,omitempty"` + KbTransferred *float64 `json:"kbTransferred,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/model_quotacountervalueupdatecontract.go b/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/model_quotacountervalueupdatecontract.go new file mode 100644 index 00000000000..27625906e0f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/model_quotacountervalueupdatecontract.go @@ -0,0 +1,8 @@ +package quotabycounterkeys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaCounterValueUpdateContract struct { + Properties *QuotaCounterValueContractProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/predicates.go b/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/predicates.go new file mode 100644 index 00000000000..b183473ffb1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/predicates.go @@ -0,0 +1,32 @@ +package quotabycounterkeys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaCounterContractOperationPredicate struct { + CounterKey *string + PeriodEndTime *string + PeriodKey *string + PeriodStartTime *string +} + +func (p QuotaCounterContractOperationPredicate) Matches(input QuotaCounterContract) bool { + + if p.CounterKey != nil && *p.CounterKey != input.CounterKey { + return false + } + + if p.PeriodEndTime != nil && *p.PeriodEndTime != input.PeriodEndTime { + return false + } + + if p.PeriodKey != nil && *p.PeriodKey != input.PeriodKey { + return false + } + + if p.PeriodStartTime != nil && *p.PeriodStartTime != input.PeriodStartTime { + return false + } + + return true +} diff --git a/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/version.go b/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/version.go new file mode 100644 index 00000000000..073fd694264 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/quotabycounterkeys/version.go @@ -0,0 +1,12 @@ +package quotabycounterkeys + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/quotabycounterkeys/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/README.md b/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/README.md new file mode 100644 index 00000000000..c907c8d3622 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/README.md @@ -0,0 +1,57 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys` Documentation + +The `quotabyperiodkeys` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys" +``` + + +### Client Initialization + +```go +client := quotabyperiodkeys.NewQuotaByPeriodKeysClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `QuotaByPeriodKeysClient.Get` + +```go +ctx := context.TODO() +id := quotabyperiodkeys.NewPeriodID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "quotaCounterKeyValue", "quotaPeriodKeyValue") + +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: `QuotaByPeriodKeysClient.Update` + +```go +ctx := context.TODO() +id := quotabyperiodkeys.NewPeriodID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "quotaCounterKeyValue", "quotaPeriodKeyValue") + +payload := quotabyperiodkeys.QuotaCounterValueUpdateContract{ + // ... +} + + +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/apimanagement/2024-05-01/quotabyperiodkeys/client.go b/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/client.go new file mode 100644 index 00000000000..338089b5c40 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/client.go @@ -0,0 +1,26 @@ +package quotabyperiodkeys + +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 QuotaByPeriodKeysClient struct { + Client *resourcemanager.Client +} + +func NewQuotaByPeriodKeysClientWithBaseURI(sdkApi sdkEnv.Api) (*QuotaByPeriodKeysClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "quotabyperiodkeys", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating QuotaByPeriodKeysClient: %+v", err) + } + + return &QuotaByPeriodKeysClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/id_period.go b/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/id_period.go new file mode 100644 index 00000000000..24a1631d595 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/id_period.go @@ -0,0 +1,148 @@ +package quotabyperiodkeys + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PeriodId{}) +} + +var _ resourceids.ResourceId = &PeriodId{} + +// PeriodId is a struct representing the Resource ID for a Period +type PeriodId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + QuotaCounterKey string + QuotaPeriodKey string +} + +// NewPeriodID returns a new PeriodId struct +func NewPeriodID(subscriptionId string, resourceGroupName string, serviceName string, quotaCounterKey string, quotaPeriodKey string) PeriodId { + return PeriodId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + QuotaCounterKey: quotaCounterKey, + QuotaPeriodKey: quotaPeriodKey, + } +} + +// ParsePeriodID parses 'input' into a PeriodId +func ParsePeriodID(input string) (*PeriodId, error) { + parser := resourceids.NewParserFromResourceIdType(&PeriodId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PeriodId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePeriodIDInsensitively parses 'input' case-insensitively into a PeriodId +// note: this method should only be used for API response data and not user input +func ParsePeriodIDInsensitively(input string) (*PeriodId, error) { + parser := resourceids.NewParserFromResourceIdType(&PeriodId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PeriodId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PeriodId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.QuotaCounterKey, ok = input.Parsed["quotaCounterKey"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "quotaCounterKey", input) + } + + if id.QuotaPeriodKey, ok = input.Parsed["quotaPeriodKey"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "quotaPeriodKey", input) + } + + return nil +} + +// ValidatePeriodID checks that 'input' can be parsed as a Period ID +func ValidatePeriodID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePeriodID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Period ID +func (id PeriodId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/quotas/%s/periods/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.QuotaCounterKey, id.QuotaPeriodKey) +} + +// Segments returns a slice of Resource ID Segments which comprise this Period ID +func (id PeriodId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticQuotas", "quotas", "quotas"), + resourceids.UserSpecifiedSegment("quotaCounterKey", "quotaCounterKeyValue"), + resourceids.StaticSegment("staticPeriods", "periods", "periods"), + resourceids.UserSpecifiedSegment("quotaPeriodKey", "quotaPeriodKeyValue"), + } +} + +// String returns a human-readable description of this Period ID +func (id PeriodId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Quota Counter Key: %q", id.QuotaCounterKey), + fmt.Sprintf("Quota Period Key: %q", id.QuotaPeriodKey), + } + return fmt.Sprintf("Period (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/id_period_test.go b/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/id_period_test.go new file mode 100644 index 00000000000..f631dd5e6ac --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/id_period_test.go @@ -0,0 +1,372 @@ +package quotabyperiodkeys + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PeriodId{} + +func TestNewPeriodID(t *testing.T) { + id := NewPeriodID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "quotaCounterKeyValue", "quotaPeriodKeyValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.QuotaCounterKey != "quotaCounterKeyValue" { + t.Fatalf("Expected %q but got %q for Segment 'QuotaCounterKey'", id.QuotaCounterKey, "quotaCounterKeyValue") + } + + if id.QuotaPeriodKey != "quotaPeriodKeyValue" { + t.Fatalf("Expected %q but got %q for Segment 'QuotaPeriodKey'", id.QuotaPeriodKey, "quotaPeriodKeyValue") + } +} + +func TestFormatPeriodID(t *testing.T) { + actual := NewPeriodID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "quotaCounterKeyValue", "quotaPeriodKeyValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/quotas/quotaCounterKeyValue/periods/quotaPeriodKeyValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePeriodID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PeriodId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/quotas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/quotas/quotaCounterKeyValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/quotas/quotaCounterKeyValue/periods", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/quotas/quotaCounterKeyValue/periods/quotaPeriodKeyValue", + Expected: &PeriodId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + QuotaCounterKey: "quotaCounterKeyValue", + QuotaPeriodKey: "quotaPeriodKeyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/quotas/quotaCounterKeyValue/periods/quotaPeriodKeyValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePeriodID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.QuotaCounterKey != v.Expected.QuotaCounterKey { + t.Fatalf("Expected %q but got %q for QuotaCounterKey", v.Expected.QuotaCounterKey, actual.QuotaCounterKey) + } + + if actual.QuotaPeriodKey != v.Expected.QuotaPeriodKey { + t.Fatalf("Expected %q but got %q for QuotaPeriodKey", v.Expected.QuotaPeriodKey, actual.QuotaPeriodKey) + } + + } +} + +func TestParsePeriodIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PeriodId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/quotas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/qUoTaS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/quotas/quotaCounterKeyValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/qUoTaS/qUoTaCoUnTeRkEyVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/quotas/quotaCounterKeyValue/periods", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/qUoTaS/qUoTaCoUnTeRkEyVaLuE/pErIoDs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/quotas/quotaCounterKeyValue/periods/quotaPeriodKeyValue", + Expected: &PeriodId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + QuotaCounterKey: "quotaCounterKeyValue", + QuotaPeriodKey: "quotaPeriodKeyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/quotas/quotaCounterKeyValue/periods/quotaPeriodKeyValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/qUoTaS/qUoTaCoUnTeRkEyVaLuE/pErIoDs/qUoTaPeRiOdKeYvAlUe", + Expected: &PeriodId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + QuotaCounterKey: "qUoTaCoUnTeRkEyVaLuE", + QuotaPeriodKey: "qUoTaPeRiOdKeYvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/qUoTaS/qUoTaCoUnTeRkEyVaLuE/pErIoDs/qUoTaPeRiOdKeYvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePeriodIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.QuotaCounterKey != v.Expected.QuotaCounterKey { + t.Fatalf("Expected %q but got %q for QuotaCounterKey", v.Expected.QuotaCounterKey, actual.QuotaCounterKey) + } + + if actual.QuotaPeriodKey != v.Expected.QuotaPeriodKey { + t.Fatalf("Expected %q but got %q for QuotaPeriodKey", v.Expected.QuotaPeriodKey, actual.QuotaPeriodKey) + } + + } +} + +func TestSegmentsForPeriodId(t *testing.T) { + segments := PeriodId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PeriodId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/method_get.go b/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/method_get.go new file mode 100644 index 00000000000..ea5a1757972 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/method_get.go @@ -0,0 +1,54 @@ +package quotabyperiodkeys + +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 *QuotaCounterContract +} + +// Get ... +func (c QuotaByPeriodKeysClient) Get(ctx context.Context, id PeriodId) (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 QuotaCounterContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/method_update.go b/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/method_update.go new file mode 100644 index 00000000000..2fc44c961e6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/method_update.go @@ -0,0 +1,58 @@ +package quotabyperiodkeys + +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 *QuotaCounterContract +} + +// Update ... +func (c QuotaByPeriodKeysClient) Update(ctx context.Context, id PeriodId, input QuotaCounterValueUpdateContract) (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 + } + + var model QuotaCounterContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/model_quotacountercontract.go b/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/model_quotacountercontract.go new file mode 100644 index 00000000000..265fa534c75 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/model_quotacountercontract.go @@ -0,0 +1,36 @@ +package quotabyperiodkeys + +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 QuotaCounterContract struct { + CounterKey string `json:"counterKey"` + PeriodEndTime string `json:"periodEndTime"` + PeriodKey string `json:"periodKey"` + PeriodStartTime string `json:"periodStartTime"` + Value *QuotaCounterValueContractProperties `json:"value,omitempty"` +} + +func (o *QuotaCounterContract) GetPeriodEndTimeAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.PeriodEndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *QuotaCounterContract) SetPeriodEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.PeriodEndTime = formatted +} + +func (o *QuotaCounterContract) GetPeriodStartTimeAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.PeriodStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *QuotaCounterContract) SetPeriodStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.PeriodStartTime = formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/model_quotacountervaluecontractproperties.go b/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/model_quotacountervaluecontractproperties.go new file mode 100644 index 00000000000..709f291e259 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/model_quotacountervaluecontractproperties.go @@ -0,0 +1,9 @@ +package quotabyperiodkeys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaCounterValueContractProperties struct { + CallsCount *int64 `json:"callsCount,omitempty"` + KbTransferred *float64 `json:"kbTransferred,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/model_quotacountervalueupdatecontract.go b/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/model_quotacountervalueupdatecontract.go new file mode 100644 index 00000000000..9c436a9bf0d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/model_quotacountervalueupdatecontract.go @@ -0,0 +1,8 @@ +package quotabyperiodkeys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaCounterValueUpdateContract struct { + Properties *QuotaCounterValueContractProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/version.go b/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/version.go new file mode 100644 index 00000000000..c15fc7afd69 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/quotabyperiodkeys/version.go @@ -0,0 +1,12 @@ +package quotabyperiodkeys + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/quotabyperiodkeys/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/region/README.md b/resource-manager/apimanagement/2024-05-01/region/README.md new file mode 100644 index 00000000000..d6ec1ba08b2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/region/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/region` Documentation + +The `region` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/region" +``` + + +### Client Initialization + +```go +client := region.NewRegionClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RegionClient.ListByService` + +```go +ctx := context.TODO() +id := region.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id)` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/region/client.go b/resource-manager/apimanagement/2024-05-01/region/client.go new file mode 100644 index 00000000000..46d4de5270d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/region/client.go @@ -0,0 +1,26 @@ +package region + +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 RegionClient struct { + Client *resourcemanager.Client +} + +func NewRegionClientWithBaseURI(sdkApi sdkEnv.Api) (*RegionClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "region", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RegionClient: %+v", err) + } + + return &RegionClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/region/id_service.go b/resource-manager/apimanagement/2024-05-01/region/id_service.go new file mode 100644 index 00000000000..287e12afddc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/region/id_service.go @@ -0,0 +1,130 @@ +package region + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/region/id_service_test.go b/resource-manager/apimanagement/2024-05-01/region/id_service_test.go new file mode 100644 index 00000000000..4d58869f2e6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/region/id_service_test.go @@ -0,0 +1,282 @@ +package region + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/region/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/region/method_listbyservice.go new file mode 100644 index 00000000000..5574a620a92 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/region/method_listbyservice.go @@ -0,0 +1,105 @@ +package region + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RegionContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []RegionContract +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c RegionClient) ListByService(ctx context.Context, id ServiceId) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/regions", 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 *[]RegionContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c RegionClient) ListByServiceComplete(ctx context.Context, id ServiceId) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, RegionContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RegionClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, predicate RegionContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]RegionContract, 0) + + resp, err := c.ListByService(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/region/model_regioncontract.go b/resource-manager/apimanagement/2024-05-01/region/model_regioncontract.go new file mode 100644 index 00000000000..976e06321c7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/region/model_regioncontract.go @@ -0,0 +1,10 @@ +package region + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegionContract struct { + IsDeleted *bool `json:"isDeleted,omitempty"` + IsMasterRegion *bool `json:"isMasterRegion,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/region/predicates.go b/resource-manager/apimanagement/2024-05-01/region/predicates.go new file mode 100644 index 00000000000..30ed56319df --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/region/predicates.go @@ -0,0 +1,27 @@ +package region + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegionContractOperationPredicate struct { + IsDeleted *bool + IsMasterRegion *bool + Name *string +} + +func (p RegionContractOperationPredicate) Matches(input RegionContract) bool { + + if p.IsDeleted != nil && (input.IsDeleted == nil || *p.IsDeleted != *input.IsDeleted) { + return false + } + + if p.IsMasterRegion != nil && (input.IsMasterRegion == nil || *p.IsMasterRegion != *input.IsMasterRegion) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + return true +} diff --git a/resource-manager/apimanagement/2024-05-01/region/version.go b/resource-manager/apimanagement/2024-05-01/region/version.go new file mode 100644 index 00000000000..4004861794f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/region/version.go @@ -0,0 +1,12 @@ +package region + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/region/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/reports/README.md b/resource-manager/apimanagement/2024-05-01/reports/README.md new file mode 100644 index 00000000000..191d91f7540 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/reports/README.md @@ -0,0 +1,155 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/reports` Documentation + +The `reports` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/reports" +``` + + +### Client Initialization + +```go +client := reports.NewReportsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReportsClient.ListByApi` + +```go +ctx := context.TODO() +id := reports.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByApi(ctx, id, reports.DefaultListByApiOperationOptions())` can be used to do batched pagination +items, err := client.ListByApiComplete(ctx, id, reports.DefaultListByApiOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ReportsClient.ListByGeo` + +```go +ctx := context.TODO() +id := reports.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByGeo(ctx, id, reports.DefaultListByGeoOperationOptions())` can be used to do batched pagination +items, err := client.ListByGeoComplete(ctx, id, reports.DefaultListByGeoOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ReportsClient.ListByOperation` + +```go +ctx := context.TODO() +id := reports.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByOperation(ctx, id, reports.DefaultListByOperationOperationOptions())` can be used to do batched pagination +items, err := client.ListByOperationComplete(ctx, id, reports.DefaultListByOperationOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ReportsClient.ListByProduct` + +```go +ctx := context.TODO() +id := reports.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByProduct(ctx, id, reports.DefaultListByProductOperationOptions())` can be used to do batched pagination +items, err := client.ListByProductComplete(ctx, id, reports.DefaultListByProductOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ReportsClient.ListByRequest` + +```go +ctx := context.TODO() +id := reports.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +read, err := client.ListByRequest(ctx, id, reports.DefaultListByRequestOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ReportsClient.ListBySubscription` + +```go +ctx := context.TODO() +id := reports.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListBySubscription(ctx, id, reports.DefaultListBySubscriptionOperationOptions())` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id, reports.DefaultListBySubscriptionOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ReportsClient.ListByTime` + +```go +ctx := context.TODO() +id := reports.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByTime(ctx, id, reports.DefaultListByTimeOperationOptions())` can be used to do batched pagination +items, err := client.ListByTimeComplete(ctx, id, reports.DefaultListByTimeOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ReportsClient.ListByUser` + +```go +ctx := context.TODO() +id := reports.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByUser(ctx, id, reports.DefaultListByUserOperationOptions())` can be used to do batched pagination +items, err := client.ListByUserComplete(ctx, id, reports.DefaultListByUserOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/reports/client.go b/resource-manager/apimanagement/2024-05-01/reports/client.go new file mode 100644 index 00000000000..7d5bde81365 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/reports/client.go @@ -0,0 +1,26 @@ +package reports + +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 ReportsClient struct { + Client *resourcemanager.Client +} + +func NewReportsClientWithBaseURI(sdkApi sdkEnv.Api) (*ReportsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "reports", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ReportsClient: %+v", err) + } + + return &ReportsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/reports/id_service.go b/resource-manager/apimanagement/2024-05-01/reports/id_service.go new file mode 100644 index 00000000000..ff6955096df --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/reports/id_service.go @@ -0,0 +1,130 @@ +package reports + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/reports/id_service_test.go b/resource-manager/apimanagement/2024-05-01/reports/id_service_test.go new file mode 100644 index 00000000000..bb3b35e415b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/reports/id_service_test.go @@ -0,0 +1,282 @@ +package reports + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/reports/method_listbyapi.go b/resource-manager/apimanagement/2024-05-01/reports/method_listbyapi.go new file mode 100644 index 00000000000..e99479d8413 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/reports/method_listbyapi.go @@ -0,0 +1,145 @@ +package reports + +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 ListByApiOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ReportRecordContract +} + +type ListByApiCompleteResult struct { + LatestHttpResponse *http.Response + Items []ReportRecordContract +} + +type ListByApiOperationOptions struct { + Filter *string + Orderby *string + Skip *int64 + Top *int64 +} + +func DefaultListByApiOperationOptions() ListByApiOperationOptions { + return ListByApiOperationOptions{} +} + +func (o ListByApiOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByApiOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByApiOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByApiCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByApiCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByApi ... +func (c ReportsClient) ListByApi(ctx context.Context, id ServiceId, options ListByApiOperationOptions) (result ListByApiOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByApiCustomPager{}, + Path: fmt.Sprintf("%s/reports/byApi", 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 *[]ReportRecordContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByApiComplete retrieves all the results into a single object +func (c ReportsClient) ListByApiComplete(ctx context.Context, id ServiceId, options ListByApiOperationOptions) (ListByApiCompleteResult, error) { + return c.ListByApiCompleteMatchingPredicate(ctx, id, options, ReportRecordContractOperationPredicate{}) +} + +// ListByApiCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ReportsClient) ListByApiCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByApiOperationOptions, predicate ReportRecordContractOperationPredicate) (result ListByApiCompleteResult, err error) { + items := make([]ReportRecordContract, 0) + + resp, err := c.ListByApi(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByApiCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/reports/method_listbygeo.go b/resource-manager/apimanagement/2024-05-01/reports/method_listbygeo.go new file mode 100644 index 00000000000..1e69c1fb509 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/reports/method_listbygeo.go @@ -0,0 +1,141 @@ +package reports + +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 ListByGeoOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ReportRecordContract +} + +type ListByGeoCompleteResult struct { + LatestHttpResponse *http.Response + Items []ReportRecordContract +} + +type ListByGeoOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByGeoOperationOptions() ListByGeoOperationOptions { + return ListByGeoOperationOptions{} +} + +func (o ListByGeoOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByGeoOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByGeoOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByGeoCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByGeoCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByGeo ... +func (c ReportsClient) ListByGeo(ctx context.Context, id ServiceId, options ListByGeoOperationOptions) (result ListByGeoOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByGeoCustomPager{}, + Path: fmt.Sprintf("%s/reports/byGeo", 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 *[]ReportRecordContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByGeoComplete retrieves all the results into a single object +func (c ReportsClient) ListByGeoComplete(ctx context.Context, id ServiceId, options ListByGeoOperationOptions) (ListByGeoCompleteResult, error) { + return c.ListByGeoCompleteMatchingPredicate(ctx, id, options, ReportRecordContractOperationPredicate{}) +} + +// ListByGeoCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ReportsClient) ListByGeoCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByGeoOperationOptions, predicate ReportRecordContractOperationPredicate) (result ListByGeoCompleteResult, err error) { + items := make([]ReportRecordContract, 0) + + resp, err := c.ListByGeo(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByGeoCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/reports/method_listbyoperation.go b/resource-manager/apimanagement/2024-05-01/reports/method_listbyoperation.go new file mode 100644 index 00000000000..bb4465b0ce3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/reports/method_listbyoperation.go @@ -0,0 +1,145 @@ +package reports + +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 ListByOperationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ReportRecordContract +} + +type ListByOperationCompleteResult struct { + LatestHttpResponse *http.Response + Items []ReportRecordContract +} + +type ListByOperationOperationOptions struct { + Filter *string + Orderby *string + Skip *int64 + Top *int64 +} + +func DefaultListByOperationOperationOptions() ListByOperationOperationOptions { + return ListByOperationOperationOptions{} +} + +func (o ListByOperationOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByOperationOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByOperationOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByOperationCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByOperationCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByOperation ... +func (c ReportsClient) ListByOperation(ctx context.Context, id ServiceId, options ListByOperationOperationOptions) (result ListByOperationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByOperationCustomPager{}, + Path: fmt.Sprintf("%s/reports/byOperation", 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 *[]ReportRecordContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByOperationComplete retrieves all the results into a single object +func (c ReportsClient) ListByOperationComplete(ctx context.Context, id ServiceId, options ListByOperationOperationOptions) (ListByOperationCompleteResult, error) { + return c.ListByOperationCompleteMatchingPredicate(ctx, id, options, ReportRecordContractOperationPredicate{}) +} + +// ListByOperationCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ReportsClient) ListByOperationCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByOperationOperationOptions, predicate ReportRecordContractOperationPredicate) (result ListByOperationCompleteResult, err error) { + items := make([]ReportRecordContract, 0) + + resp, err := c.ListByOperation(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByOperationCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/reports/method_listbyproduct.go b/resource-manager/apimanagement/2024-05-01/reports/method_listbyproduct.go new file mode 100644 index 00000000000..3a6df43c7b4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/reports/method_listbyproduct.go @@ -0,0 +1,145 @@ +package reports + +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 ListByProductOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ReportRecordContract +} + +type ListByProductCompleteResult struct { + LatestHttpResponse *http.Response + Items []ReportRecordContract +} + +type ListByProductOperationOptions struct { + Filter *string + Orderby *string + Skip *int64 + Top *int64 +} + +func DefaultListByProductOperationOptions() ListByProductOperationOptions { + return ListByProductOperationOptions{} +} + +func (o ListByProductOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByProductOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByProductOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByProductCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByProductCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByProduct ... +func (c ReportsClient) ListByProduct(ctx context.Context, id ServiceId, options ListByProductOperationOptions) (result ListByProductOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByProductCustomPager{}, + Path: fmt.Sprintf("%s/reports/byProduct", 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 *[]ReportRecordContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByProductComplete retrieves all the results into a single object +func (c ReportsClient) ListByProductComplete(ctx context.Context, id ServiceId, options ListByProductOperationOptions) (ListByProductCompleteResult, error) { + return c.ListByProductCompleteMatchingPredicate(ctx, id, options, ReportRecordContractOperationPredicate{}) +} + +// ListByProductCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ReportsClient) ListByProductCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByProductOperationOptions, predicate ReportRecordContractOperationPredicate) (result ListByProductCompleteResult, err error) { + items := make([]ReportRecordContract, 0) + + resp, err := c.ListByProduct(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByProductCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/reports/method_listbyrequest.go b/resource-manager/apimanagement/2024-05-01/reports/method_listbyrequest.go new file mode 100644 index 00000000000..265c2670114 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/reports/method_listbyrequest.go @@ -0,0 +1,91 @@ +package reports + +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 ListByRequestOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RequestReportCollection +} + +type ListByRequestOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByRequestOperationOptions() ListByRequestOperationOptions { + return ListByRequestOperationOptions{} +} + +func (o ListByRequestOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByRequestOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByRequestOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByRequest ... +func (c ReportsClient) ListByRequest(ctx context.Context, id ServiceId, options ListByRequestOperationOptions) (result ListByRequestOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/reports/byRequest", 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 RequestReportCollection + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/reports/method_listbysubscription.go b/resource-manager/apimanagement/2024-05-01/reports/method_listbysubscription.go new file mode 100644 index 00000000000..1e7ffadeafd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/reports/method_listbysubscription.go @@ -0,0 +1,145 @@ +package reports + +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 ListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ReportRecordContract +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []ReportRecordContract +} + +type ListBySubscriptionOperationOptions struct { + Filter *string + Orderby *string + Skip *int64 + 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.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListBySubscriptionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySubscriptionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySubscription ... +func (c ReportsClient) ListBySubscription(ctx context.Context, id ServiceId, options ListBySubscriptionOperationOptions) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListBySubscriptionCustomPager{}, + Path: fmt.Sprintf("%s/reports/bySubscription", 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 *[]ReportRecordContract `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 ReportsClient) ListBySubscriptionComplete(ctx context.Context, id ServiceId, options ListBySubscriptionOperationOptions) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, options, ReportRecordContractOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ReportsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListBySubscriptionOperationOptions, predicate ReportRecordContractOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]ReportRecordContract, 0) + + resp, err := c.ListBySubscription(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/reports/method_listbytime.go b/resource-manager/apimanagement/2024-05-01/reports/method_listbytime.go new file mode 100644 index 00000000000..629527e4e8b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/reports/method_listbytime.go @@ -0,0 +1,149 @@ +package reports + +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 ListByTimeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ReportRecordContract +} + +type ListByTimeCompleteResult struct { + LatestHttpResponse *http.Response + Items []ReportRecordContract +} + +type ListByTimeOperationOptions struct { + Filter *string + Interval *string + Orderby *string + Skip *int64 + Top *int64 +} + +func DefaultListByTimeOperationOptions() ListByTimeOperationOptions { + return ListByTimeOperationOptions{} +} + +func (o ListByTimeOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByTimeOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByTimeOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Interval != nil { + out.Append("interval", fmt.Sprintf("%v", *o.Interval)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByTimeCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByTimeCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByTime ... +func (c ReportsClient) ListByTime(ctx context.Context, id ServiceId, options ListByTimeOperationOptions) (result ListByTimeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByTimeCustomPager{}, + Path: fmt.Sprintf("%s/reports/byTime", 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 *[]ReportRecordContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByTimeComplete retrieves all the results into a single object +func (c ReportsClient) ListByTimeComplete(ctx context.Context, id ServiceId, options ListByTimeOperationOptions) (ListByTimeCompleteResult, error) { + return c.ListByTimeCompleteMatchingPredicate(ctx, id, options, ReportRecordContractOperationPredicate{}) +} + +// ListByTimeCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ReportsClient) ListByTimeCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByTimeOperationOptions, predicate ReportRecordContractOperationPredicate) (result ListByTimeCompleteResult, err error) { + items := make([]ReportRecordContract, 0) + + resp, err := c.ListByTime(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByTimeCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/reports/method_listbyuser.go b/resource-manager/apimanagement/2024-05-01/reports/method_listbyuser.go new file mode 100644 index 00000000000..0751d4a40cb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/reports/method_listbyuser.go @@ -0,0 +1,145 @@ +package reports + +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 ListByUserOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ReportRecordContract +} + +type ListByUserCompleteResult struct { + LatestHttpResponse *http.Response + Items []ReportRecordContract +} + +type ListByUserOperationOptions struct { + Filter *string + Orderby *string + Skip *int64 + Top *int64 +} + +func DefaultListByUserOperationOptions() ListByUserOperationOptions { + return ListByUserOperationOptions{} +} + +func (o ListByUserOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByUserOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByUserOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByUserCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByUserCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByUser ... +func (c ReportsClient) ListByUser(ctx context.Context, id ServiceId, options ListByUserOperationOptions) (result ListByUserOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByUserCustomPager{}, + Path: fmt.Sprintf("%s/reports/byUser", 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 *[]ReportRecordContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByUserComplete retrieves all the results into a single object +func (c ReportsClient) ListByUserComplete(ctx context.Context, id ServiceId, options ListByUserOperationOptions) (ListByUserCompleteResult, error) { + return c.ListByUserCompleteMatchingPredicate(ctx, id, options, ReportRecordContractOperationPredicate{}) +} + +// ListByUserCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ReportsClient) ListByUserCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByUserOperationOptions, predicate ReportRecordContractOperationPredicate) (result ListByUserCompleteResult, err error) { + items := make([]ReportRecordContract, 0) + + resp, err := c.ListByUser(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByUserCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/reports/model_reportrecordcontract.go b/resource-manager/apimanagement/2024-05-01/reports/model_reportrecordcontract.go new file mode 100644 index 00000000000..8035b71c158 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/reports/model_reportrecordcontract.go @@ -0,0 +1,51 @@ +package reports + +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 ReportRecordContract struct { + ApiId *string `json:"apiId,omitempty"` + ApiRegion *string `json:"apiRegion,omitempty"` + ApiTimeAvg *float64 `json:"apiTimeAvg,omitempty"` + ApiTimeMax *float64 `json:"apiTimeMax,omitempty"` + ApiTimeMin *float64 `json:"apiTimeMin,omitempty"` + Bandwidth *int64 `json:"bandwidth,omitempty"` + CacheHitCount *int64 `json:"cacheHitCount,omitempty"` + CacheMissCount *int64 `json:"cacheMissCount,omitempty"` + CallCountBlocked *int64 `json:"callCountBlocked,omitempty"` + CallCountFailed *int64 `json:"callCountFailed,omitempty"` + CallCountOther *int64 `json:"callCountOther,omitempty"` + CallCountSuccess *int64 `json:"callCountSuccess,omitempty"` + CallCountTotal *int64 `json:"callCountTotal,omitempty"` + Country *string `json:"country,omitempty"` + Interval *string `json:"interval,omitempty"` + Name *string `json:"name,omitempty"` + OperationId *string `json:"operationId,omitempty"` + ProductId *string `json:"productId,omitempty"` + Region *string `json:"region,omitempty"` + ServiceTimeAvg *float64 `json:"serviceTimeAvg,omitempty"` + ServiceTimeMax *float64 `json:"serviceTimeMax,omitempty"` + ServiceTimeMin *float64 `json:"serviceTimeMin,omitempty"` + SubscriptionId *string `json:"subscriptionId,omitempty"` + Timestamp *string `json:"timestamp,omitempty"` + UserId *string `json:"userId,omitempty"` + Zip *string `json:"zip,omitempty"` +} + +func (o *ReportRecordContract) GetTimestampAsTime() (*time.Time, error) { + if o.Timestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Timestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *ReportRecordContract) SetTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Timestamp = &formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/reports/model_requestreportcollection.go b/resource-manager/apimanagement/2024-05-01/reports/model_requestreportcollection.go new file mode 100644 index 00000000000..0baac4a6a7a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/reports/model_requestreportcollection.go @@ -0,0 +1,9 @@ +package reports + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RequestReportCollection struct { + Count *int64 `json:"count,omitempty"` + Value *[]RequestReportRecordContract `json:"value,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/reports/model_requestreportrecordcontract.go b/resource-manager/apimanagement/2024-05-01/reports/model_requestreportrecordcontract.go new file mode 100644 index 00000000000..fdf49f78e5a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/reports/model_requestreportrecordcontract.go @@ -0,0 +1,43 @@ +package reports + +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 RequestReportRecordContract struct { + ApiId *string `json:"apiId,omitempty"` + ApiRegion *string `json:"apiRegion,omitempty"` + ApiTime *float64 `json:"apiTime,omitempty"` + BackendResponseCode *string `json:"backendResponseCode,omitempty"` + Cache *string `json:"cache,omitempty"` + IPAddress *string `json:"ipAddress,omitempty"` + Method *string `json:"method,omitempty"` + OperationId *string `json:"operationId,omitempty"` + ProductId *string `json:"productId,omitempty"` + RequestId *string `json:"requestId,omitempty"` + RequestSize *int64 `json:"requestSize,omitempty"` + ResponseCode *int64 `json:"responseCode,omitempty"` + ResponseSize *int64 `json:"responseSize,omitempty"` + ServiceTime *float64 `json:"serviceTime,omitempty"` + SubscriptionId *string `json:"subscriptionId,omitempty"` + Timestamp *string `json:"timestamp,omitempty"` + Url *string `json:"url,omitempty"` + UserId *string `json:"userId,omitempty"` +} + +func (o *RequestReportRecordContract) GetTimestampAsTime() (*time.Time, error) { + if o.Timestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Timestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *RequestReportRecordContract) SetTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Timestamp = &formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/reports/predicates.go b/resource-manager/apimanagement/2024-05-01/reports/predicates.go new file mode 100644 index 00000000000..752c5ee660a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/reports/predicates.go @@ -0,0 +1,142 @@ +package reports + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReportRecordContractOperationPredicate struct { + ApiId *string + ApiRegion *string + ApiTimeAvg *float64 + ApiTimeMax *float64 + ApiTimeMin *float64 + Bandwidth *int64 + CacheHitCount *int64 + CacheMissCount *int64 + CallCountBlocked *int64 + CallCountFailed *int64 + CallCountOther *int64 + CallCountSuccess *int64 + CallCountTotal *int64 + Country *string + Interval *string + Name *string + OperationId *string + ProductId *string + Region *string + ServiceTimeAvg *float64 + ServiceTimeMax *float64 + ServiceTimeMin *float64 + SubscriptionId *string + Timestamp *string + UserId *string + Zip *string +} + +func (p ReportRecordContractOperationPredicate) Matches(input ReportRecordContract) bool { + + if p.ApiId != nil && (input.ApiId == nil || *p.ApiId != *input.ApiId) { + return false + } + + if p.ApiRegion != nil && (input.ApiRegion == nil || *p.ApiRegion != *input.ApiRegion) { + return false + } + + if p.ApiTimeAvg != nil && (input.ApiTimeAvg == nil || *p.ApiTimeAvg != *input.ApiTimeAvg) { + return false + } + + if p.ApiTimeMax != nil && (input.ApiTimeMax == nil || *p.ApiTimeMax != *input.ApiTimeMax) { + return false + } + + if p.ApiTimeMin != nil && (input.ApiTimeMin == nil || *p.ApiTimeMin != *input.ApiTimeMin) { + return false + } + + if p.Bandwidth != nil && (input.Bandwidth == nil || *p.Bandwidth != *input.Bandwidth) { + return false + } + + if p.CacheHitCount != nil && (input.CacheHitCount == nil || *p.CacheHitCount != *input.CacheHitCount) { + return false + } + + if p.CacheMissCount != nil && (input.CacheMissCount == nil || *p.CacheMissCount != *input.CacheMissCount) { + return false + } + + if p.CallCountBlocked != nil && (input.CallCountBlocked == nil || *p.CallCountBlocked != *input.CallCountBlocked) { + return false + } + + if p.CallCountFailed != nil && (input.CallCountFailed == nil || *p.CallCountFailed != *input.CallCountFailed) { + return false + } + + if p.CallCountOther != nil && (input.CallCountOther == nil || *p.CallCountOther != *input.CallCountOther) { + return false + } + + if p.CallCountSuccess != nil && (input.CallCountSuccess == nil || *p.CallCountSuccess != *input.CallCountSuccess) { + return false + } + + if p.CallCountTotal != nil && (input.CallCountTotal == nil || *p.CallCountTotal != *input.CallCountTotal) { + return false + } + + if p.Country != nil && (input.Country == nil || *p.Country != *input.Country) { + return false + } + + if p.Interval != nil && (input.Interval == nil || *p.Interval != *input.Interval) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.OperationId != nil && (input.OperationId == nil || *p.OperationId != *input.OperationId) { + return false + } + + if p.ProductId != nil && (input.ProductId == nil || *p.ProductId != *input.ProductId) { + return false + } + + if p.Region != nil && (input.Region == nil || *p.Region != *input.Region) { + return false + } + + if p.ServiceTimeAvg != nil && (input.ServiceTimeAvg == nil || *p.ServiceTimeAvg != *input.ServiceTimeAvg) { + return false + } + + if p.ServiceTimeMax != nil && (input.ServiceTimeMax == nil || *p.ServiceTimeMax != *input.ServiceTimeMax) { + return false + } + + if p.ServiceTimeMin != nil && (input.ServiceTimeMin == nil || *p.ServiceTimeMin != *input.ServiceTimeMin) { + return false + } + + if p.SubscriptionId != nil && (input.SubscriptionId == nil || *p.SubscriptionId != *input.SubscriptionId) { + return false + } + + if p.Timestamp != nil && (input.Timestamp == nil || *p.Timestamp != *input.Timestamp) { + return false + } + + if p.UserId != nil && (input.UserId == nil || *p.UserId != *input.UserId) { + return false + } + + if p.Zip != nil && (input.Zip == nil || *p.Zip != *input.Zip) { + return false + } + + return true +} diff --git a/resource-manager/apimanagement/2024-05-01/reports/version.go b/resource-manager/apimanagement/2024-05-01/reports/version.go new file mode 100644 index 00000000000..4b39f7b2a00 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/reports/version.go @@ -0,0 +1,12 @@ +package reports + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/reports/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/schema/README.md b/resource-manager/apimanagement/2024-05-01/schema/README.md new file mode 100644 index 00000000000..2ae965a4f9a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/README.md @@ -0,0 +1,184 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/schema` Documentation + +The `schema` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/schema" +``` + + +### Client Initialization + +```go +client := schema.NewSchemaClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SchemaClient.GlobalSchemaCreateOrUpdate` + +```go +ctx := context.TODO() +id := schema.NewSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "schemaIdValue") + +payload := schema.GlobalSchemaContract{ + // ... +} + + +if err := client.GlobalSchemaCreateOrUpdateThenPoll(ctx, id, payload, schema.DefaultGlobalSchemaCreateOrUpdateOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `SchemaClient.GlobalSchemaDelete` + +```go +ctx := context.TODO() +id := schema.NewSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "schemaIdValue") + +read, err := client.GlobalSchemaDelete(ctx, id, schema.DefaultGlobalSchemaDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SchemaClient.GlobalSchemaGet` + +```go +ctx := context.TODO() +id := schema.NewSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "schemaIdValue") + +read, err := client.GlobalSchemaGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SchemaClient.GlobalSchemaGetEntityTag` + +```go +ctx := context.TODO() +id := schema.NewSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "schemaIdValue") + +read, err := client.GlobalSchemaGetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SchemaClient.GlobalSchemaListByService` + +```go +ctx := context.TODO() +id := schema.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.GlobalSchemaListByService(ctx, id, schema.DefaultGlobalSchemaListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.GlobalSchemaListByServiceComplete(ctx, id, schema.DefaultGlobalSchemaListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SchemaClient.WorkspaceGlobalSchemaCreateOrUpdate` + +```go +ctx := context.TODO() +id := schema.NewWorkspaceSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "schemaIdValue") + +payload := schema.GlobalSchemaContract{ + // ... +} + + +if err := client.WorkspaceGlobalSchemaCreateOrUpdateThenPoll(ctx, id, payload, schema.DefaultWorkspaceGlobalSchemaCreateOrUpdateOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `SchemaClient.WorkspaceGlobalSchemaDelete` + +```go +ctx := context.TODO() +id := schema.NewWorkspaceSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "schemaIdValue") + +read, err := client.WorkspaceGlobalSchemaDelete(ctx, id, schema.DefaultWorkspaceGlobalSchemaDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SchemaClient.WorkspaceGlobalSchemaGet` + +```go +ctx := context.TODO() +id := schema.NewWorkspaceSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "schemaIdValue") + +read, err := client.WorkspaceGlobalSchemaGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SchemaClient.WorkspaceGlobalSchemaGetEntityTag` + +```go +ctx := context.TODO() +id := schema.NewWorkspaceSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "schemaIdValue") + +read, err := client.WorkspaceGlobalSchemaGetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SchemaClient.WorkspaceGlobalSchemaListByService` + +```go +ctx := context.TODO() +id := schema.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +// alternatively `client.WorkspaceGlobalSchemaListByService(ctx, id, schema.DefaultWorkspaceGlobalSchemaListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.WorkspaceGlobalSchemaListByServiceComplete(ctx, id, schema.DefaultWorkspaceGlobalSchemaListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/schema/client.go b/resource-manager/apimanagement/2024-05-01/schema/client.go new file mode 100644 index 00000000000..3d872ecf7a1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/client.go @@ -0,0 +1,26 @@ +package schema + +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 SchemaClient struct { + Client *resourcemanager.Client +} + +func NewSchemaClientWithBaseURI(sdkApi sdkEnv.Api) (*SchemaClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "schema", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SchemaClient: %+v", err) + } + + return &SchemaClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/schema/constants.go b/resource-manager/apimanagement/2024-05-01/schema/constants.go new file mode 100644 index 00000000000..fc6c0c9faf6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/constants.go @@ -0,0 +1,51 @@ +package schema + +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 SchemaType string + +const ( + SchemaTypeJson SchemaType = "json" + SchemaTypeXml SchemaType = "xml" +) + +func PossibleValuesForSchemaType() []string { + return []string{ + string(SchemaTypeJson), + string(SchemaTypeXml), + } +} + +func (s *SchemaType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSchemaType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSchemaType(input string) (*SchemaType, error) { + vals := map[string]SchemaType{ + "json": SchemaTypeJson, + "xml": SchemaTypeXml, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SchemaType(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/schema/id_schema.go b/resource-manager/apimanagement/2024-05-01/schema/id_schema.go new file mode 100644 index 00000000000..bb6238dd767 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/id_schema.go @@ -0,0 +1,139 @@ +package schema + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SchemaId{}) +} + +var _ resourceids.ResourceId = &SchemaId{} + +// SchemaId is a struct representing the Resource ID for a Schema +type SchemaId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + SchemaId string +} + +// NewSchemaID returns a new SchemaId struct +func NewSchemaID(subscriptionId string, resourceGroupName string, serviceName string, schemaId string) SchemaId { + return SchemaId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + SchemaId: schemaId, + } +} + +// ParseSchemaID parses 'input' into a SchemaId +func ParseSchemaID(input string) (*SchemaId, error) { + parser := resourceids.NewParserFromResourceIdType(&SchemaId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SchemaId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSchemaIDInsensitively parses 'input' case-insensitively into a SchemaId +// note: this method should only be used for API response data and not user input +func ParseSchemaIDInsensitively(input string) (*SchemaId, error) { + parser := resourceids.NewParserFromResourceIdType(&SchemaId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SchemaId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SchemaId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.SchemaId, ok = input.Parsed["schemaId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaId", input) + } + + return nil +} + +// ValidateSchemaID checks that 'input' can be parsed as a Schema ID +func ValidateSchemaID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSchemaID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Schema ID +func (id SchemaId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/schemas/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.SchemaId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Schema ID +func (id SchemaId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaId", "schemaIdValue"), + } +} + +// String returns a human-readable description of this Schema ID +func (id SchemaId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Schema: %q", id.SchemaId), + } + return fmt.Sprintf("Schema (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/schema/id_schema_test.go b/resource-manager/apimanagement/2024-05-01/schema/id_schema_test.go new file mode 100644 index 00000000000..bbe67a14a42 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/id_schema_test.go @@ -0,0 +1,327 @@ +package schema + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SchemaId{} + +func TestNewSchemaID(t *testing.T) { + id := NewSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "schemaIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.SchemaId != "schemaIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaId'", id.SchemaId, "schemaIdValue") + } +} + +func TestFormatSchemaID(t *testing.T) { + actual := NewSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "schemaIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/schemas/schemaIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSchemaID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SchemaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/schemas", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/schemas/schemaIdValue", + Expected: &SchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + SchemaId: "schemaIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/schemas/schemaIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSchemaID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.SchemaId != v.Expected.SchemaId { + t.Fatalf("Expected %q but got %q for SchemaId", v.Expected.SchemaId, actual.SchemaId) + } + + } +} + +func TestParseSchemaIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SchemaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/sChEmAs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/schemas/schemaIdValue", + Expected: &SchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + SchemaId: "schemaIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/schemas/schemaIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/sChEmAs/sChEmAiDvAlUe", + Expected: &SchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + SchemaId: "sChEmAiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/sChEmAs/sChEmAiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSchemaIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.SchemaId != v.Expected.SchemaId { + t.Fatalf("Expected %q but got %q for SchemaId", v.Expected.SchemaId, actual.SchemaId) + } + + } +} + +func TestSegmentsForSchemaId(t *testing.T) { + segments := SchemaId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SchemaId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/schema/id_service.go b/resource-manager/apimanagement/2024-05-01/schema/id_service.go new file mode 100644 index 00000000000..11419aeb835 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/id_service.go @@ -0,0 +1,130 @@ +package schema + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/schema/id_service_test.go b/resource-manager/apimanagement/2024-05-01/schema/id_service_test.go new file mode 100644 index 00000000000..5f67eb63f5d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/id_service_test.go @@ -0,0 +1,282 @@ +package schema + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/schema/id_workspace.go b/resource-manager/apimanagement/2024-05-01/schema/id_workspace.go new file mode 100644 index 00000000000..f4096e5456a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/id_workspace.go @@ -0,0 +1,139 @@ +package schema + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/schema/id_workspace_test.go b/resource-manager/apimanagement/2024-05-01/schema/id_workspace_test.go new file mode 100644 index 00000000000..034f681fa83 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/id_workspace_test.go @@ -0,0 +1,327 @@ +package schema + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/schema/id_workspaceschema.go b/resource-manager/apimanagement/2024-05-01/schema/id_workspaceschema.go new file mode 100644 index 00000000000..25f35d2ce89 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/id_workspaceschema.go @@ -0,0 +1,148 @@ +package schema + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceSchemaId{}) +} + +var _ resourceids.ResourceId = &WorkspaceSchemaId{} + +// WorkspaceSchemaId is a struct representing the Resource ID for a Workspace Schema +type WorkspaceSchemaId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + SchemaId string +} + +// NewWorkspaceSchemaID returns a new WorkspaceSchemaId struct +func NewWorkspaceSchemaID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, schemaId string) WorkspaceSchemaId { + return WorkspaceSchemaId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + SchemaId: schemaId, + } +} + +// ParseWorkspaceSchemaID parses 'input' into a WorkspaceSchemaId +func ParseWorkspaceSchemaID(input string) (*WorkspaceSchemaId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceSchemaId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceSchemaId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceSchemaIDInsensitively parses 'input' case-insensitively into a WorkspaceSchemaId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceSchemaIDInsensitively(input string) (*WorkspaceSchemaId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceSchemaId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceSchemaId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceSchemaId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.SchemaId, ok = input.Parsed["schemaId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaId", input) + } + + return nil +} + +// ValidateWorkspaceSchemaID checks that 'input' can be parsed as a Workspace Schema ID +func ValidateWorkspaceSchemaID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceSchemaID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Schema ID +func (id WorkspaceSchemaId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/schemas/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.SchemaId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Schema ID +func (id WorkspaceSchemaId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaId", "schemaIdValue"), + } +} + +// String returns a human-readable description of this Workspace Schema ID +func (id WorkspaceSchemaId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Schema: %q", id.SchemaId), + } + return fmt.Sprintf("Workspace Schema (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/schema/id_workspaceschema_test.go b/resource-manager/apimanagement/2024-05-01/schema/id_workspaceschema_test.go new file mode 100644 index 00000000000..4abbaa0feba --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/id_workspaceschema_test.go @@ -0,0 +1,372 @@ +package schema + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceSchemaId{} + +func TestNewWorkspaceSchemaID(t *testing.T) { + id := NewWorkspaceSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "schemaIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.SchemaId != "schemaIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaId'", id.SchemaId, "schemaIdValue") + } +} + +func TestFormatWorkspaceSchemaID(t *testing.T) { + actual := NewWorkspaceSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "schemaIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/schemas/schemaIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceSchemaID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceSchemaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/schemas", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/schemas/schemaIdValue", + Expected: &WorkspaceSchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + SchemaId: "schemaIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/schemas/schemaIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceSchemaID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.SchemaId != v.Expected.SchemaId { + t.Fatalf("Expected %q but got %q for SchemaId", v.Expected.SchemaId, actual.SchemaId) + } + + } +} + +func TestParseWorkspaceSchemaIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceSchemaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/sChEmAs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/schemas/schemaIdValue", + Expected: &WorkspaceSchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + SchemaId: "schemaIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/schemas/schemaIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/sChEmAs/sChEmAiDvAlUe", + Expected: &WorkspaceSchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + SchemaId: "sChEmAiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/sChEmAs/sChEmAiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceSchemaIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.SchemaId != v.Expected.SchemaId { + t.Fatalf("Expected %q but got %q for SchemaId", v.Expected.SchemaId, actual.SchemaId) + } + + } +} + +func TestSegmentsForWorkspaceSchemaId(t *testing.T) { + segments := WorkspaceSchemaId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceSchemaId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/schema/method_globalschemacreateorupdate.go b/resource-manager/apimanagement/2024-05-01/schema/method_globalschemacreateorupdate.go new file mode 100644 index 00000000000..6f6a15cfe78 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/method_globalschemacreateorupdate.go @@ -0,0 +1,103 @@ +package schema + +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 GlobalSchemaCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *GlobalSchemaContract +} + +type GlobalSchemaCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultGlobalSchemaCreateOrUpdateOperationOptions() GlobalSchemaCreateOrUpdateOperationOptions { + return GlobalSchemaCreateOrUpdateOperationOptions{} +} + +func (o GlobalSchemaCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o GlobalSchemaCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o GlobalSchemaCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// GlobalSchemaCreateOrUpdate ... +func (c SchemaClient) GlobalSchemaCreateOrUpdate(ctx context.Context, id SchemaId, input GlobalSchemaContract, options GlobalSchemaCreateOrUpdateOperationOptions) (result GlobalSchemaCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 +} + +// GlobalSchemaCreateOrUpdateThenPoll performs GlobalSchemaCreateOrUpdate then polls until it's completed +func (c SchemaClient) GlobalSchemaCreateOrUpdateThenPoll(ctx context.Context, id SchemaId, input GlobalSchemaContract, options GlobalSchemaCreateOrUpdateOperationOptions) error { + result, err := c.GlobalSchemaCreateOrUpdate(ctx, id, input, options) + if err != nil { + return fmt.Errorf("performing GlobalSchemaCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after GlobalSchemaCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/apimanagement/2024-05-01/schema/method_globalschemadelete.go b/resource-manager/apimanagement/2024-05-01/schema/method_globalschemadelete.go new file mode 100644 index 00000000000..234fcfcb78f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/method_globalschemadelete.go @@ -0,0 +1,76 @@ +package schema + +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 GlobalSchemaDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type GlobalSchemaDeleteOperationOptions struct { + IfMatch *string +} + +func DefaultGlobalSchemaDeleteOperationOptions() GlobalSchemaDeleteOperationOptions { + return GlobalSchemaDeleteOperationOptions{} +} + +func (o GlobalSchemaDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o GlobalSchemaDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o GlobalSchemaDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// GlobalSchemaDelete ... +func (c SchemaClient) GlobalSchemaDelete(ctx context.Context, id SchemaId, options GlobalSchemaDeleteOperationOptions) (result GlobalSchemaDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/schema/method_globalschemaget.go b/resource-manager/apimanagement/2024-05-01/schema/method_globalschemaget.go new file mode 100644 index 00000000000..d2ec4344b20 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/method_globalschemaget.go @@ -0,0 +1,54 @@ +package schema + +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 GlobalSchemaGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GlobalSchemaContract +} + +// GlobalSchemaGet ... +func (c SchemaClient) GlobalSchemaGet(ctx context.Context, id SchemaId) (result GlobalSchemaGetOperationResponse, 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 GlobalSchemaContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/schema/method_globalschemagetentitytag.go b/resource-manager/apimanagement/2024-05-01/schema/method_globalschemagetentitytag.go new file mode 100644 index 00000000000..b62a3956afc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/method_globalschemagetentitytag.go @@ -0,0 +1,46 @@ +package schema + +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 GlobalSchemaGetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GlobalSchemaGetEntityTag ... +func (c SchemaClient) GlobalSchemaGetEntityTag(ctx context.Context, id SchemaId) (result GlobalSchemaGetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/schema/method_globalschemalistbyservice.go b/resource-manager/apimanagement/2024-05-01/schema/method_globalschemalistbyservice.go new file mode 100644 index 00000000000..7797c6a6b8f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/method_globalschemalistbyservice.go @@ -0,0 +1,141 @@ +package schema + +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 GlobalSchemaListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GlobalSchemaContract +} + +type GlobalSchemaListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []GlobalSchemaContract +} + +type GlobalSchemaListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultGlobalSchemaListByServiceOperationOptions() GlobalSchemaListByServiceOperationOptions { + return GlobalSchemaListByServiceOperationOptions{} +} + +func (o GlobalSchemaListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o GlobalSchemaListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o GlobalSchemaListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type GlobalSchemaListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *GlobalSchemaListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// GlobalSchemaListByService ... +func (c SchemaClient) GlobalSchemaListByService(ctx context.Context, id ServiceId, options GlobalSchemaListByServiceOperationOptions) (result GlobalSchemaListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &GlobalSchemaListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/schemas", 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 *[]GlobalSchemaContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GlobalSchemaListByServiceComplete retrieves all the results into a single object +func (c SchemaClient) GlobalSchemaListByServiceComplete(ctx context.Context, id ServiceId, options GlobalSchemaListByServiceOperationOptions) (GlobalSchemaListByServiceCompleteResult, error) { + return c.GlobalSchemaListByServiceCompleteMatchingPredicate(ctx, id, options, GlobalSchemaContractOperationPredicate{}) +} + +// GlobalSchemaListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SchemaClient) GlobalSchemaListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options GlobalSchemaListByServiceOperationOptions, predicate GlobalSchemaContractOperationPredicate) (result GlobalSchemaListByServiceCompleteResult, err error) { + items := make([]GlobalSchemaContract, 0) + + resp, err := c.GlobalSchemaListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GlobalSchemaListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/schema/method_workspaceglobalschemacreateorupdate.go b/resource-manager/apimanagement/2024-05-01/schema/method_workspaceglobalschemacreateorupdate.go new file mode 100644 index 00000000000..99be8ac48c4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/method_workspaceglobalschemacreateorupdate.go @@ -0,0 +1,103 @@ +package schema + +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 WorkspaceGlobalSchemaCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *GlobalSchemaContract +} + +type WorkspaceGlobalSchemaCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceGlobalSchemaCreateOrUpdateOperationOptions() WorkspaceGlobalSchemaCreateOrUpdateOperationOptions { + return WorkspaceGlobalSchemaCreateOrUpdateOperationOptions{} +} + +func (o WorkspaceGlobalSchemaCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceGlobalSchemaCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceGlobalSchemaCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceGlobalSchemaCreateOrUpdate ... +func (c SchemaClient) WorkspaceGlobalSchemaCreateOrUpdate(ctx context.Context, id WorkspaceSchemaId, input GlobalSchemaContract, options WorkspaceGlobalSchemaCreateOrUpdateOperationOptions) (result WorkspaceGlobalSchemaCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 +} + +// WorkspaceGlobalSchemaCreateOrUpdateThenPoll performs WorkspaceGlobalSchemaCreateOrUpdate then polls until it's completed +func (c SchemaClient) WorkspaceGlobalSchemaCreateOrUpdateThenPoll(ctx context.Context, id WorkspaceSchemaId, input GlobalSchemaContract, options WorkspaceGlobalSchemaCreateOrUpdateOperationOptions) error { + result, err := c.WorkspaceGlobalSchemaCreateOrUpdate(ctx, id, input, options) + if err != nil { + return fmt.Errorf("performing WorkspaceGlobalSchemaCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after WorkspaceGlobalSchemaCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/apimanagement/2024-05-01/schema/method_workspaceglobalschemadelete.go b/resource-manager/apimanagement/2024-05-01/schema/method_workspaceglobalschemadelete.go new file mode 100644 index 00000000000..a8aab3185b1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/method_workspaceglobalschemadelete.go @@ -0,0 +1,76 @@ +package schema + +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 WorkspaceGlobalSchemaDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type WorkspaceGlobalSchemaDeleteOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceGlobalSchemaDeleteOperationOptions() WorkspaceGlobalSchemaDeleteOperationOptions { + return WorkspaceGlobalSchemaDeleteOperationOptions{} +} + +func (o WorkspaceGlobalSchemaDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceGlobalSchemaDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceGlobalSchemaDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceGlobalSchemaDelete ... +func (c SchemaClient) WorkspaceGlobalSchemaDelete(ctx context.Context, id WorkspaceSchemaId, options WorkspaceGlobalSchemaDeleteOperationOptions) (result WorkspaceGlobalSchemaDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/schema/method_workspaceglobalschemaget.go b/resource-manager/apimanagement/2024-05-01/schema/method_workspaceglobalschemaget.go new file mode 100644 index 00000000000..73828cf65b6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/method_workspaceglobalschemaget.go @@ -0,0 +1,54 @@ +package schema + +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 WorkspaceGlobalSchemaGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GlobalSchemaContract +} + +// WorkspaceGlobalSchemaGet ... +func (c SchemaClient) WorkspaceGlobalSchemaGet(ctx context.Context, id WorkspaceSchemaId) (result WorkspaceGlobalSchemaGetOperationResponse, 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 GlobalSchemaContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/schema/method_workspaceglobalschemagetentitytag.go b/resource-manager/apimanagement/2024-05-01/schema/method_workspaceglobalschemagetentitytag.go new file mode 100644 index 00000000000..b1283fa3b7b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/method_workspaceglobalschemagetentitytag.go @@ -0,0 +1,46 @@ +package schema + +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 WorkspaceGlobalSchemaGetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceGlobalSchemaGetEntityTag ... +func (c SchemaClient) WorkspaceGlobalSchemaGetEntityTag(ctx context.Context, id WorkspaceSchemaId) (result WorkspaceGlobalSchemaGetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/schema/method_workspaceglobalschemalistbyservice.go b/resource-manager/apimanagement/2024-05-01/schema/method_workspaceglobalschemalistbyservice.go new file mode 100644 index 00000000000..aeae5549ab2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/method_workspaceglobalschemalistbyservice.go @@ -0,0 +1,141 @@ +package schema + +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 WorkspaceGlobalSchemaListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GlobalSchemaContract +} + +type WorkspaceGlobalSchemaListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []GlobalSchemaContract +} + +type WorkspaceGlobalSchemaListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultWorkspaceGlobalSchemaListByServiceOperationOptions() WorkspaceGlobalSchemaListByServiceOperationOptions { + return WorkspaceGlobalSchemaListByServiceOperationOptions{} +} + +func (o WorkspaceGlobalSchemaListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceGlobalSchemaListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceGlobalSchemaListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspaceGlobalSchemaListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceGlobalSchemaListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceGlobalSchemaListByService ... +func (c SchemaClient) WorkspaceGlobalSchemaListByService(ctx context.Context, id WorkspaceId, options WorkspaceGlobalSchemaListByServiceOperationOptions) (result WorkspaceGlobalSchemaListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspaceGlobalSchemaListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/schemas", 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 *[]GlobalSchemaContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceGlobalSchemaListByServiceComplete retrieves all the results into a single object +func (c SchemaClient) WorkspaceGlobalSchemaListByServiceComplete(ctx context.Context, id WorkspaceId, options WorkspaceGlobalSchemaListByServiceOperationOptions) (WorkspaceGlobalSchemaListByServiceCompleteResult, error) { + return c.WorkspaceGlobalSchemaListByServiceCompleteMatchingPredicate(ctx, id, options, GlobalSchemaContractOperationPredicate{}) +} + +// WorkspaceGlobalSchemaListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SchemaClient) WorkspaceGlobalSchemaListByServiceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options WorkspaceGlobalSchemaListByServiceOperationOptions, predicate GlobalSchemaContractOperationPredicate) (result WorkspaceGlobalSchemaListByServiceCompleteResult, err error) { + items := make([]GlobalSchemaContract, 0) + + resp, err := c.WorkspaceGlobalSchemaListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceGlobalSchemaListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/schema/model_globalschemacontract.go b/resource-manager/apimanagement/2024-05-01/schema/model_globalschemacontract.go new file mode 100644 index 00000000000..4d72a7e9bf8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/model_globalschemacontract.go @@ -0,0 +1,11 @@ +package schema + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GlobalSchemaContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *GlobalSchemaContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/schema/model_globalschemacontractproperties.go b/resource-manager/apimanagement/2024-05-01/schema/model_globalschemacontractproperties.go new file mode 100644 index 00000000000..efd52177b2a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/model_globalschemacontractproperties.go @@ -0,0 +1,12 @@ +package schema + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GlobalSchemaContractProperties struct { + Description *string `json:"description,omitempty"` + Document *interface{} `json:"document,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + SchemaType SchemaType `json:"schemaType"` + Value *interface{} `json:"value,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/schema/predicates.go b/resource-manager/apimanagement/2024-05-01/schema/predicates.go new file mode 100644 index 00000000000..7f16ac143ee --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/predicates.go @@ -0,0 +1,27 @@ +package schema + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GlobalSchemaContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p GlobalSchemaContractOperationPredicate) Matches(input GlobalSchemaContract) 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/apimanagement/2024-05-01/schema/version.go b/resource-manager/apimanagement/2024-05-01/schema/version.go new file mode 100644 index 00000000000..466e794d288 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/schema/version.go @@ -0,0 +1,12 @@ +package schema + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/schema/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/signinsettings/README.md b/resource-manager/apimanagement/2024-05-01/signinsettings/README.md new file mode 100644 index 00000000000..235f4193c05 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/signinsettings/README.md @@ -0,0 +1,94 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/signinsettings` Documentation + +The `signinsettings` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/signinsettings" +``` + + +### Client Initialization + +```go +client := signinsettings.NewSignInSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SignInSettingsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := signinsettings.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +payload := signinsettings.PortalSigninSettings{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, signinsettings.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SignInSettingsClient.Get` + +```go +ctx := context.TODO() +id := signinsettings.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +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: `SignInSettingsClient.GetEntityTag` + +```go +ctx := context.TODO() +id := signinsettings.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SignInSettingsClient.Update` + +```go +ctx := context.TODO() +id := signinsettings.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +payload := signinsettings.PortalSigninSettings{ + // ... +} + + +read, err := client.Update(ctx, id, payload, signinsettings.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/signinsettings/client.go b/resource-manager/apimanagement/2024-05-01/signinsettings/client.go new file mode 100644 index 00000000000..a21dfcdddd2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/signinsettings/client.go @@ -0,0 +1,26 @@ +package signinsettings + +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 SignInSettingsClient struct { + Client *resourcemanager.Client +} + +func NewSignInSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*SignInSettingsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "signinsettings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SignInSettingsClient: %+v", err) + } + + return &SignInSettingsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/signinsettings/id_service.go b/resource-manager/apimanagement/2024-05-01/signinsettings/id_service.go new file mode 100644 index 00000000000..fd18eb71e2f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/signinsettings/id_service.go @@ -0,0 +1,130 @@ +package signinsettings + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/signinsettings/id_service_test.go b/resource-manager/apimanagement/2024-05-01/signinsettings/id_service_test.go new file mode 100644 index 00000000000..d2f1e7900ef --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/signinsettings/id_service_test.go @@ -0,0 +1,282 @@ +package signinsettings + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/signinsettings/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/signinsettings/method_createorupdate.go new file mode 100644 index 00000000000..7354010fc89 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/signinsettings/method_createorupdate.go @@ -0,0 +1,87 @@ +package signinsettings + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PortalSigninSettings +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c SignInSettingsClient) CreateOrUpdate(ctx context.Context, id ServiceId, input PortalSigninSettings, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + Path: fmt.Sprintf("%s/portalsettings/signin", 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 PortalSigninSettings + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/signinsettings/method_get.go b/resource-manager/apimanagement/2024-05-01/signinsettings/method_get.go new file mode 100644 index 00000000000..1de8b5e5963 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/signinsettings/method_get.go @@ -0,0 +1,55 @@ +package signinsettings + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PortalSigninSettings +} + +// Get ... +func (c SignInSettingsClient) Get(ctx context.Context, id ServiceId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/portalsettings/signin", 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 PortalSigninSettings + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/signinsettings/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/signinsettings/method_getentitytag.go new file mode 100644 index 00000000000..25861ccf2a4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/signinsettings/method_getentitytag.go @@ -0,0 +1,47 @@ +package signinsettings + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c SignInSettingsClient) GetEntityTag(ctx context.Context, id ServiceId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: fmt.Sprintf("%s/portalsettings/signin", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/signinsettings/method_update.go b/resource-manager/apimanagement/2024-05-01/signinsettings/method_update.go new file mode 100644 index 00000000000..1c0af5a3508 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/signinsettings/method_update.go @@ -0,0 +1,79 @@ +package signinsettings + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c SignInSettingsClient) Update(ctx context.Context, id ServiceId, input PortalSigninSettings, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + Path: fmt.Sprintf("%s/portalsettings/signin", 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/apimanagement/2024-05-01/signinsettings/model_portalsigninsettingproperties.go b/resource-manager/apimanagement/2024-05-01/signinsettings/model_portalsigninsettingproperties.go new file mode 100644 index 00000000000..c97ccbce5c6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/signinsettings/model_portalsigninsettingproperties.go @@ -0,0 +1,8 @@ +package signinsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PortalSigninSettingProperties struct { + Enabled *bool `json:"enabled,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/signinsettings/model_portalsigninsettings.go b/resource-manager/apimanagement/2024-05-01/signinsettings/model_portalsigninsettings.go new file mode 100644 index 00000000000..cb7c961c1cf --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/signinsettings/model_portalsigninsettings.go @@ -0,0 +1,11 @@ +package signinsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PortalSigninSettings struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PortalSigninSettingProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/signinsettings/version.go b/resource-manager/apimanagement/2024-05-01/signinsettings/version.go new file mode 100644 index 00000000000..d51779befcb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/signinsettings/version.go @@ -0,0 +1,12 @@ +package signinsettings + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/signinsettings/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/signupsettings/README.md b/resource-manager/apimanagement/2024-05-01/signupsettings/README.md new file mode 100644 index 00000000000..a75a4f1d4b4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/signupsettings/README.md @@ -0,0 +1,94 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/signupsettings` Documentation + +The `signupsettings` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/signupsettings" +``` + + +### Client Initialization + +```go +client := signupsettings.NewSignUpSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SignUpSettingsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := signupsettings.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +payload := signupsettings.PortalSignupSettings{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, signupsettings.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SignUpSettingsClient.Get` + +```go +ctx := context.TODO() +id := signupsettings.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +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: `SignUpSettingsClient.GetEntityTag` + +```go +ctx := context.TODO() +id := signupsettings.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SignUpSettingsClient.Update` + +```go +ctx := context.TODO() +id := signupsettings.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +payload := signupsettings.PortalSignupSettings{ + // ... +} + + +read, err := client.Update(ctx, id, payload, signupsettings.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/signupsettings/client.go b/resource-manager/apimanagement/2024-05-01/signupsettings/client.go new file mode 100644 index 00000000000..2d9452823e3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/signupsettings/client.go @@ -0,0 +1,26 @@ +package signupsettings + +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 SignUpSettingsClient struct { + Client *resourcemanager.Client +} + +func NewSignUpSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*SignUpSettingsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "signupsettings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SignUpSettingsClient: %+v", err) + } + + return &SignUpSettingsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/signupsettings/id_service.go b/resource-manager/apimanagement/2024-05-01/signupsettings/id_service.go new file mode 100644 index 00000000000..eeefe5b42b7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/signupsettings/id_service.go @@ -0,0 +1,130 @@ +package signupsettings + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/signupsettings/id_service_test.go b/resource-manager/apimanagement/2024-05-01/signupsettings/id_service_test.go new file mode 100644 index 00000000000..ebd5f357058 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/signupsettings/id_service_test.go @@ -0,0 +1,282 @@ +package signupsettings + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/signupsettings/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/signupsettings/method_createorupdate.go new file mode 100644 index 00000000000..8d57367d2f5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/signupsettings/method_createorupdate.go @@ -0,0 +1,87 @@ +package signupsettings + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PortalSignupSettings +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c SignUpSettingsClient) CreateOrUpdate(ctx context.Context, id ServiceId, input PortalSignupSettings, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + Path: fmt.Sprintf("%s/portalsettings/signup", 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 PortalSignupSettings + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/signupsettings/method_get.go b/resource-manager/apimanagement/2024-05-01/signupsettings/method_get.go new file mode 100644 index 00000000000..e9062643330 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/signupsettings/method_get.go @@ -0,0 +1,55 @@ +package signupsettings + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PortalSignupSettings +} + +// Get ... +func (c SignUpSettingsClient) Get(ctx context.Context, id ServiceId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/portalsettings/signup", 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 PortalSignupSettings + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/signupsettings/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/signupsettings/method_getentitytag.go new file mode 100644 index 00000000000..c664f2c2ea8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/signupsettings/method_getentitytag.go @@ -0,0 +1,47 @@ +package signupsettings + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c SignUpSettingsClient) GetEntityTag(ctx context.Context, id ServiceId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: fmt.Sprintf("%s/portalsettings/signup", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/signupsettings/method_update.go b/resource-manager/apimanagement/2024-05-01/signupsettings/method_update.go new file mode 100644 index 00000000000..8d8918d3324 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/signupsettings/method_update.go @@ -0,0 +1,79 @@ +package signupsettings + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c SignUpSettingsClient) Update(ctx context.Context, id ServiceId, input PortalSignupSettings, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + Path: fmt.Sprintf("%s/portalsettings/signup", 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/apimanagement/2024-05-01/signupsettings/model_portalsignupsettings.go b/resource-manager/apimanagement/2024-05-01/signupsettings/model_portalsignupsettings.go new file mode 100644 index 00000000000..9519f3132c9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/signupsettings/model_portalsignupsettings.go @@ -0,0 +1,11 @@ +package signupsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PortalSignupSettings struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PortalSignupSettingsProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/signupsettings/model_portalsignupsettingsproperties.go b/resource-manager/apimanagement/2024-05-01/signupsettings/model_portalsignupsettingsproperties.go new file mode 100644 index 00000000000..f011af153f8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/signupsettings/model_portalsignupsettingsproperties.go @@ -0,0 +1,9 @@ +package signupsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PortalSignupSettingsProperties struct { + Enabled *bool `json:"enabled,omitempty"` + TermsOfService *TermsOfServiceProperties `json:"termsOfService,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/signupsettings/model_termsofserviceproperties.go b/resource-manager/apimanagement/2024-05-01/signupsettings/model_termsofserviceproperties.go new file mode 100644 index 00000000000..13c71bb8ee4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/signupsettings/model_termsofserviceproperties.go @@ -0,0 +1,10 @@ +package signupsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TermsOfServiceProperties struct { + ConsentRequired *bool `json:"consentRequired,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + Text *string `json:"text,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/signupsettings/version.go b/resource-manager/apimanagement/2024-05-01/signupsettings/version.go new file mode 100644 index 00000000000..18496c4242f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/signupsettings/version.go @@ -0,0 +1,12 @@ +package signupsettings + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/signupsettings/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/skus/README.md b/resource-manager/apimanagement/2024-05-01/skus/README.md new file mode 100644 index 00000000000..55aef9cf3ba --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/skus/README.md @@ -0,0 +1,38 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/skus` Documentation + +The `skus` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/skus" +``` + + +### Client Initialization + +```go +client := skus.NewSkusClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SkusClient.ApiManagementSkusList` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ApiManagementSkusList(ctx, id)` can be used to do batched pagination +items, err := client.ApiManagementSkusListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/skus/client.go b/resource-manager/apimanagement/2024-05-01/skus/client.go new file mode 100644 index 00000000000..90cd04245b3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/skus/client.go @@ -0,0 +1,26 @@ +package skus + +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 SkusClient struct { + Client *resourcemanager.Client +} + +func NewSkusClientWithBaseURI(sdkApi sdkEnv.Api) (*SkusClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "skus", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SkusClient: %+v", err) + } + + return &SkusClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/skus/constants.go b/resource-manager/apimanagement/2024-05-01/skus/constants.go new file mode 100644 index 00000000000..97daf30eeec --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/skus/constants.go @@ -0,0 +1,136 @@ +package skus + +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 ApiManagementSkuCapacityScaleType string + +const ( + ApiManagementSkuCapacityScaleTypeAutomatic ApiManagementSkuCapacityScaleType = "Automatic" + ApiManagementSkuCapacityScaleTypeManual ApiManagementSkuCapacityScaleType = "Manual" + ApiManagementSkuCapacityScaleTypeNone ApiManagementSkuCapacityScaleType = "None" +) + +func PossibleValuesForApiManagementSkuCapacityScaleType() []string { + return []string{ + string(ApiManagementSkuCapacityScaleTypeAutomatic), + string(ApiManagementSkuCapacityScaleTypeManual), + string(ApiManagementSkuCapacityScaleTypeNone), + } +} + +func (s *ApiManagementSkuCapacityScaleType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseApiManagementSkuCapacityScaleType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseApiManagementSkuCapacityScaleType(input string) (*ApiManagementSkuCapacityScaleType, error) { + vals := map[string]ApiManagementSkuCapacityScaleType{ + "automatic": ApiManagementSkuCapacityScaleTypeAutomatic, + "manual": ApiManagementSkuCapacityScaleTypeManual, + "none": ApiManagementSkuCapacityScaleTypeNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ApiManagementSkuCapacityScaleType(input) + return &out, nil +} + +type ApiManagementSkuRestrictionsReasonCode string + +const ( + ApiManagementSkuRestrictionsReasonCodeNotAvailableForSubscription ApiManagementSkuRestrictionsReasonCode = "NotAvailableForSubscription" + ApiManagementSkuRestrictionsReasonCodeQuotaId ApiManagementSkuRestrictionsReasonCode = "QuotaId" +) + +func PossibleValuesForApiManagementSkuRestrictionsReasonCode() []string { + return []string{ + string(ApiManagementSkuRestrictionsReasonCodeNotAvailableForSubscription), + string(ApiManagementSkuRestrictionsReasonCodeQuotaId), + } +} + +func (s *ApiManagementSkuRestrictionsReasonCode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseApiManagementSkuRestrictionsReasonCode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseApiManagementSkuRestrictionsReasonCode(input string) (*ApiManagementSkuRestrictionsReasonCode, error) { + vals := map[string]ApiManagementSkuRestrictionsReasonCode{ + "notavailableforsubscription": ApiManagementSkuRestrictionsReasonCodeNotAvailableForSubscription, + "quotaid": ApiManagementSkuRestrictionsReasonCodeQuotaId, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ApiManagementSkuRestrictionsReasonCode(input) + return &out, nil +} + +type ApiManagementSkuRestrictionsType string + +const ( + ApiManagementSkuRestrictionsTypeLocation ApiManagementSkuRestrictionsType = "Location" + ApiManagementSkuRestrictionsTypeZone ApiManagementSkuRestrictionsType = "Zone" +) + +func PossibleValuesForApiManagementSkuRestrictionsType() []string { + return []string{ + string(ApiManagementSkuRestrictionsTypeLocation), + string(ApiManagementSkuRestrictionsTypeZone), + } +} + +func (s *ApiManagementSkuRestrictionsType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseApiManagementSkuRestrictionsType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseApiManagementSkuRestrictionsType(input string) (*ApiManagementSkuRestrictionsType, error) { + vals := map[string]ApiManagementSkuRestrictionsType{ + "location": ApiManagementSkuRestrictionsTypeLocation, + "zone": ApiManagementSkuRestrictionsTypeZone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ApiManagementSkuRestrictionsType(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/skus/method_apimanagementskuslist.go b/resource-manager/apimanagement/2024-05-01/skus/method_apimanagementskuslist.go new file mode 100644 index 00000000000..9c429654469 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/skus/method_apimanagementskuslist.go @@ -0,0 +1,106 @@ +package skus + +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 ApiManagementSkusListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ApiManagementSku +} + +type ApiManagementSkusListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ApiManagementSku +} + +type ApiManagementSkusListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ApiManagementSkusListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ApiManagementSkusList ... +func (c SkusClient) ApiManagementSkusList(ctx context.Context, id commonids.SubscriptionId) (result ApiManagementSkusListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ApiManagementSkusListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.ApiManagement/skus", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ApiManagementSku `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ApiManagementSkusListComplete retrieves all the results into a single object +func (c SkusClient) ApiManagementSkusListComplete(ctx context.Context, id commonids.SubscriptionId) (ApiManagementSkusListCompleteResult, error) { + return c.ApiManagementSkusListCompleteMatchingPredicate(ctx, id, ApiManagementSkuOperationPredicate{}) +} + +// ApiManagementSkusListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SkusClient) ApiManagementSkusListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ApiManagementSkuOperationPredicate) (result ApiManagementSkusListCompleteResult, err error) { + items := make([]ApiManagementSku, 0) + + resp, err := c.ApiManagementSkusList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ApiManagementSkusListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/skus/model_apimanagementsku.go b/resource-manager/apimanagement/2024-05-01/skus/model_apimanagementsku.go new file mode 100644 index 00000000000..e209c4b59f1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/skus/model_apimanagementsku.go @@ -0,0 +1,20 @@ +package skus + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementSku struct { + ApiVersions *[]string `json:"apiVersions,omitempty"` + Capabilities *[]ApiManagementSkuCapabilities `json:"capabilities,omitempty"` + Capacity *ApiManagementSkuCapacity `json:"capacity,omitempty"` + Costs *[]ApiManagementSkuCosts `json:"costs,omitempty"` + Family *string `json:"family,omitempty"` + Kind *string `json:"kind,omitempty"` + LocationInfo *[]ApiManagementSkuLocationInfo `json:"locationInfo,omitempty"` + Locations *[]string `json:"locations,omitempty"` + Name *string `json:"name,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + Restrictions *[]ApiManagementSkuRestrictions `json:"restrictions,omitempty"` + Size *string `json:"size,omitempty"` + Tier *string `json:"tier,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/skus/model_apimanagementskucapabilities.go b/resource-manager/apimanagement/2024-05-01/skus/model_apimanagementskucapabilities.go new file mode 100644 index 00000000000..a10d3d75a5c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/skus/model_apimanagementskucapabilities.go @@ -0,0 +1,9 @@ +package skus + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementSkuCapabilities struct { + Name *string `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/skus/model_apimanagementskucapacity.go b/resource-manager/apimanagement/2024-05-01/skus/model_apimanagementskucapacity.go new file mode 100644 index 00000000000..5499e9a15a1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/skus/model_apimanagementskucapacity.go @@ -0,0 +1,11 @@ +package skus + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementSkuCapacity struct { + Default *int64 `json:"default,omitempty"` + Maximum *int64 `json:"maximum,omitempty"` + Minimum *int64 `json:"minimum,omitempty"` + ScaleType *ApiManagementSkuCapacityScaleType `json:"scaleType,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/skus/model_apimanagementskucosts.go b/resource-manager/apimanagement/2024-05-01/skus/model_apimanagementskucosts.go new file mode 100644 index 00000000000..983a5b372ba --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/skus/model_apimanagementskucosts.go @@ -0,0 +1,10 @@ +package skus + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementSkuCosts struct { + ExtendedUnit *string `json:"extendedUnit,omitempty"` + MeterID *string `json:"meterID,omitempty"` + Quantity *int64 `json:"quantity,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/skus/model_apimanagementskulocationinfo.go b/resource-manager/apimanagement/2024-05-01/skus/model_apimanagementskulocationinfo.go new file mode 100644 index 00000000000..c54de0a969d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/skus/model_apimanagementskulocationinfo.go @@ -0,0 +1,14 @@ +package skus + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementSkuLocationInfo struct { + Location *string `json:"location,omitempty"` + ZoneDetails *[]ApiManagementSkuZoneDetails `json:"zoneDetails,omitempty"` + Zones *zones.Schema `json:"zones,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/skus/model_apimanagementskurestrictioninfo.go b/resource-manager/apimanagement/2024-05-01/skus/model_apimanagementskurestrictioninfo.go new file mode 100644 index 00000000000..7e3b4042793 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/skus/model_apimanagementskurestrictioninfo.go @@ -0,0 +1,13 @@ +package skus + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementSkuRestrictionInfo struct { + Locations *[]string `json:"locations,omitempty"` + Zones *zones.Schema `json:"zones,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/skus/model_apimanagementskurestrictions.go b/resource-manager/apimanagement/2024-05-01/skus/model_apimanagementskurestrictions.go new file mode 100644 index 00000000000..c8fe92fdfdd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/skus/model_apimanagementskurestrictions.go @@ -0,0 +1,11 @@ +package skus + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementSkuRestrictions struct { + ReasonCode *ApiManagementSkuRestrictionsReasonCode `json:"reasonCode,omitempty"` + RestrictionInfo *ApiManagementSkuRestrictionInfo `json:"restrictionInfo,omitempty"` + Type *ApiManagementSkuRestrictionsType `json:"type,omitempty"` + Values *[]string `json:"values,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/skus/model_apimanagementskuzonedetails.go b/resource-manager/apimanagement/2024-05-01/skus/model_apimanagementskuzonedetails.go new file mode 100644 index 00000000000..9992477e0fc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/skus/model_apimanagementskuzonedetails.go @@ -0,0 +1,9 @@ +package skus + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementSkuZoneDetails struct { + Capabilities *[]ApiManagementSkuCapabilities `json:"capabilities,omitempty"` + Name *[]string `json:"name,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/skus/predicates.go b/resource-manager/apimanagement/2024-05-01/skus/predicates.go new file mode 100644 index 00000000000..76a27562558 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/skus/predicates.go @@ -0,0 +1,42 @@ +package skus + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiManagementSkuOperationPredicate struct { + Family *string + Kind *string + Name *string + ResourceType *string + Size *string + Tier *string +} + +func (p ApiManagementSkuOperationPredicate) Matches(input ApiManagementSku) bool { + + if p.Family != nil && (input.Family == nil || *p.Family != *input.Family) { + return false + } + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.ResourceType != nil && (input.ResourceType == nil || *p.ResourceType != *input.ResourceType) { + return false + } + + if p.Size != nil && (input.Size == nil || *p.Size != *input.Size) { + return false + } + + if p.Tier != nil && (input.Tier == nil || *p.Tier != *input.Tier) { + return false + } + + return true +} diff --git a/resource-manager/apimanagement/2024-05-01/skus/version.go b/resource-manager/apimanagement/2024-05-01/skus/version.go new file mode 100644 index 00000000000..2340bd89ab8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/skus/version.go @@ -0,0 +1,12 @@ +package skus + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/skus/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/README.md b/resource-manager/apimanagement/2024-05-01/subscription/README.md new file mode 100644 index 00000000000..f75b2537236 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/README.md @@ -0,0 +1,346 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/subscription` Documentation + +The `subscription` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/subscription" +``` + + +### Client Initialization + +```go +client := subscription.NewSubscriptionClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SubscriptionClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := subscription.NewSubscriptions2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "subscriptionValue") + +payload := subscription.SubscriptionCreateParameters{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, subscription.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionClient.Delete` + +```go +ctx := context.TODO() +id := subscription.NewSubscriptions2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "subscriptionValue") + +read, err := client.Delete(ctx, id, subscription.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionClient.Get` + +```go +ctx := context.TODO() +id := subscription.NewSubscriptions2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "subscriptionValue") + +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: `SubscriptionClient.GetEntityTag` + +```go +ctx := context.TODO() +id := subscription.NewSubscriptions2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "subscriptionValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionClient.List` + +```go +ctx := context.TODO() +id := subscription.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.List(ctx, id, subscription.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, subscription.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SubscriptionClient.ListSecrets` + +```go +ctx := context.TODO() +id := subscription.NewSubscriptions2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "subscriptionValue") + +read, err := client.ListSecrets(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionClient.RegeneratePrimaryKey` + +```go +ctx := context.TODO() +id := subscription.NewSubscriptions2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "subscriptionValue") + +read, err := client.RegeneratePrimaryKey(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionClient.RegenerateSecondaryKey` + +```go +ctx := context.TODO() +id := subscription.NewSubscriptions2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "subscriptionValue") + +read, err := client.RegenerateSecondaryKey(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionClient.Update` + +```go +ctx := context.TODO() +id := subscription.NewSubscriptions2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "subscriptionValue") + +payload := subscription.SubscriptionUpdateParameters{ + // ... +} + + +read, err := client.Update(ctx, id, payload, subscription.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionClient.UserSubscriptionGet` + +```go +ctx := context.TODO() +id := subscription.NewUserSubscriptions2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue", "subscriptionValue") + +read, err := client.UserSubscriptionGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionClient.WorkspaceSubscriptionCreateOrUpdate` + +```go +ctx := context.TODO() +id := subscription.NewWorkspaceSubscriptions2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "subscriptionValue") + +payload := subscription.SubscriptionCreateParameters{ + // ... +} + + +read, err := client.WorkspaceSubscriptionCreateOrUpdate(ctx, id, payload, subscription.DefaultWorkspaceSubscriptionCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionClient.WorkspaceSubscriptionDelete` + +```go +ctx := context.TODO() +id := subscription.NewWorkspaceSubscriptions2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "subscriptionValue") + +read, err := client.WorkspaceSubscriptionDelete(ctx, id, subscription.DefaultWorkspaceSubscriptionDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionClient.WorkspaceSubscriptionGet` + +```go +ctx := context.TODO() +id := subscription.NewWorkspaceSubscriptions2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "subscriptionValue") + +read, err := client.WorkspaceSubscriptionGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionClient.WorkspaceSubscriptionGetEntityTag` + +```go +ctx := context.TODO() +id := subscription.NewWorkspaceSubscriptions2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "subscriptionValue") + +read, err := client.WorkspaceSubscriptionGetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionClient.WorkspaceSubscriptionList` + +```go +ctx := context.TODO() +id := subscription.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +// alternatively `client.WorkspaceSubscriptionList(ctx, id, subscription.DefaultWorkspaceSubscriptionListOperationOptions())` can be used to do batched pagination +items, err := client.WorkspaceSubscriptionListComplete(ctx, id, subscription.DefaultWorkspaceSubscriptionListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SubscriptionClient.WorkspaceSubscriptionListSecrets` + +```go +ctx := context.TODO() +id := subscription.NewWorkspaceSubscriptions2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "subscriptionValue") + +read, err := client.WorkspaceSubscriptionListSecrets(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionClient.WorkspaceSubscriptionRegeneratePrimaryKey` + +```go +ctx := context.TODO() +id := subscription.NewWorkspaceSubscriptions2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "subscriptionValue") + +read, err := client.WorkspaceSubscriptionRegeneratePrimaryKey(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionClient.WorkspaceSubscriptionRegenerateSecondaryKey` + +```go +ctx := context.TODO() +id := subscription.NewWorkspaceSubscriptions2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "subscriptionValue") + +read, err := client.WorkspaceSubscriptionRegenerateSecondaryKey(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionClient.WorkspaceSubscriptionUpdate` + +```go +ctx := context.TODO() +id := subscription.NewWorkspaceSubscriptions2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "subscriptionValue") + +payload := subscription.SubscriptionUpdateParameters{ + // ... +} + + +read, err := client.WorkspaceSubscriptionUpdate(ctx, id, payload, subscription.DefaultWorkspaceSubscriptionUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/subscription/client.go b/resource-manager/apimanagement/2024-05-01/subscription/client.go new file mode 100644 index 00000000000..9885434f9dd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/client.go @@ -0,0 +1,26 @@ +package subscription + +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 SubscriptionClient struct { + Client *resourcemanager.Client +} + +func NewSubscriptionClientWithBaseURI(sdkApi sdkEnv.Api) (*SubscriptionClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "subscription", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SubscriptionClient: %+v", err) + } + + return &SubscriptionClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/constants.go b/resource-manager/apimanagement/2024-05-01/subscription/constants.go new file mode 100644 index 00000000000..71ac415eaca --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/constants.go @@ -0,0 +1,104 @@ +package subscription + +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 AppType string + +const ( + AppTypeDeveloperPortal AppType = "developerPortal" + AppTypePortal AppType = "portal" +) + +func PossibleValuesForAppType() []string { + return []string{ + string(AppTypeDeveloperPortal), + string(AppTypePortal), + } +} + +func (s *AppType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAppType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAppType(input string) (*AppType, error) { + vals := map[string]AppType{ + "developerportal": AppTypeDeveloperPortal, + "portal": AppTypePortal, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AppType(input) + return &out, nil +} + +type SubscriptionState string + +const ( + SubscriptionStateActive SubscriptionState = "active" + SubscriptionStateCancelled SubscriptionState = "cancelled" + SubscriptionStateExpired SubscriptionState = "expired" + SubscriptionStateRejected SubscriptionState = "rejected" + SubscriptionStateSubmitted SubscriptionState = "submitted" + SubscriptionStateSuspended SubscriptionState = "suspended" +) + +func PossibleValuesForSubscriptionState() []string { + return []string{ + string(SubscriptionStateActive), + string(SubscriptionStateCancelled), + string(SubscriptionStateExpired), + string(SubscriptionStateRejected), + string(SubscriptionStateSubmitted), + string(SubscriptionStateSuspended), + } +} + +func (s *SubscriptionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSubscriptionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSubscriptionState(input string) (*SubscriptionState, error) { + vals := map[string]SubscriptionState{ + "active": SubscriptionStateActive, + "cancelled": SubscriptionStateCancelled, + "expired": SubscriptionStateExpired, + "rejected": SubscriptionStateRejected, + "submitted": SubscriptionStateSubmitted, + "suspended": SubscriptionStateSuspended, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SubscriptionState(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/id_service.go b/resource-manager/apimanagement/2024-05-01/subscription/id_service.go new file mode 100644 index 00000000000..eae18b83523 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/id_service.go @@ -0,0 +1,130 @@ +package subscription + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/id_service_test.go b/resource-manager/apimanagement/2024-05-01/subscription/id_service_test.go new file mode 100644 index 00000000000..4e5ef99624b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/id_service_test.go @@ -0,0 +1,282 @@ +package subscription + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/id_subscriptions2.go b/resource-manager/apimanagement/2024-05-01/subscription/id_subscriptions2.go new file mode 100644 index 00000000000..92e8dcc65f1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/id_subscriptions2.go @@ -0,0 +1,139 @@ +package subscription + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&Subscriptions2Id{}) +} + +var _ resourceids.ResourceId = &Subscriptions2Id{} + +// Subscriptions2Id is a struct representing the Resource ID for a Subscriptions 2 +type Subscriptions2Id struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + SubscriptionName string +} + +// NewSubscriptions2ID returns a new Subscriptions2Id struct +func NewSubscriptions2ID(subscriptionId string, resourceGroupName string, serviceName string, subscriptionName string) Subscriptions2Id { + return Subscriptions2Id{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + SubscriptionName: subscriptionName, + } +} + +// ParseSubscriptions2ID parses 'input' into a Subscriptions2Id +func ParseSubscriptions2ID(input string) (*Subscriptions2Id, error) { + parser := resourceids.NewParserFromResourceIdType(&Subscriptions2Id{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := Subscriptions2Id{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSubscriptions2IDInsensitively parses 'input' case-insensitively into a Subscriptions2Id +// note: this method should only be used for API response data and not user input +func ParseSubscriptions2IDInsensitively(input string) (*Subscriptions2Id, error) { + parser := resourceids.NewParserFromResourceIdType(&Subscriptions2Id{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := Subscriptions2Id{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *Subscriptions2Id) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.SubscriptionName, ok = input.Parsed["subscriptionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionName", input) + } + + return nil +} + +// ValidateSubscriptions2ID checks that 'input' can be parsed as a Subscriptions 2 ID +func ValidateSubscriptions2ID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSubscriptions2ID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Subscriptions 2 ID +func (id Subscriptions2Id) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/subscriptions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.SubscriptionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Subscriptions 2 ID +func (id Subscriptions2Id) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticSubscriptions2", "subscriptions", "subscriptions"), + resourceids.UserSpecifiedSegment("subscriptionName", "subscriptionValue"), + } +} + +// String returns a human-readable description of this Subscriptions 2 ID +func (id Subscriptions2Id) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Subscription Name: %q", id.SubscriptionName), + } + return fmt.Sprintf("Subscriptions 2 (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/id_subscriptions2_test.go b/resource-manager/apimanagement/2024-05-01/subscription/id_subscriptions2_test.go new file mode 100644 index 00000000000..f39b28196d1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/id_subscriptions2_test.go @@ -0,0 +1,327 @@ +package subscription + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &Subscriptions2Id{} + +func TestNewSubscriptions2ID(t *testing.T) { + id := NewSubscriptions2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "subscriptionValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.SubscriptionName != "subscriptionValue" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionName'", id.SubscriptionName, "subscriptionValue") + } +} + +func TestFormatSubscriptions2ID(t *testing.T) { + actual := NewSubscriptions2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "subscriptionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/subscriptions/subscriptionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSubscriptions2ID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *Subscriptions2Id + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/subscriptions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/subscriptions/subscriptionValue", + Expected: &Subscriptions2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + SubscriptionName: "subscriptionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/subscriptions/subscriptionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSubscriptions2ID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.SubscriptionName != v.Expected.SubscriptionName { + t.Fatalf("Expected %q but got %q for SubscriptionName", v.Expected.SubscriptionName, actual.SubscriptionName) + } + + } +} + +func TestParseSubscriptions2IDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *Subscriptions2Id + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/sUbScRiPtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/subscriptions/subscriptionValue", + Expected: &Subscriptions2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + SubscriptionName: "subscriptionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/subscriptions/subscriptionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/sUbScRiPtIoNs/sUbScRiPtIoNvAlUe", + Expected: &Subscriptions2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + SubscriptionName: "sUbScRiPtIoNvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/sUbScRiPtIoNs/sUbScRiPtIoNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSubscriptions2IDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.SubscriptionName != v.Expected.SubscriptionName { + t.Fatalf("Expected %q but got %q for SubscriptionName", v.Expected.SubscriptionName, actual.SubscriptionName) + } + + } +} + +func TestSegmentsForSubscriptions2Id(t *testing.T) { + segments := Subscriptions2Id{}.Segments() + if len(segments) == 0 { + t.Fatalf("Subscriptions2Id has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/id_usersubscriptions2.go b/resource-manager/apimanagement/2024-05-01/subscription/id_usersubscriptions2.go new file mode 100644 index 00000000000..07412cdb651 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/id_usersubscriptions2.go @@ -0,0 +1,148 @@ +package subscription + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&UserSubscriptions2Id{}) +} + +var _ resourceids.ResourceId = &UserSubscriptions2Id{} + +// UserSubscriptions2Id is a struct representing the Resource ID for a User Subscriptions 2 +type UserSubscriptions2Id struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + UserId string + SubscriptionName string +} + +// NewUserSubscriptions2ID returns a new UserSubscriptions2Id struct +func NewUserSubscriptions2ID(subscriptionId string, resourceGroupName string, serviceName string, userId string, subscriptionName string) UserSubscriptions2Id { + return UserSubscriptions2Id{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + UserId: userId, + SubscriptionName: subscriptionName, + } +} + +// ParseUserSubscriptions2ID parses 'input' into a UserSubscriptions2Id +func ParseUserSubscriptions2ID(input string) (*UserSubscriptions2Id, error) { + parser := resourceids.NewParserFromResourceIdType(&UserSubscriptions2Id{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UserSubscriptions2Id{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseUserSubscriptions2IDInsensitively parses 'input' case-insensitively into a UserSubscriptions2Id +// note: this method should only be used for API response data and not user input +func ParseUserSubscriptions2IDInsensitively(input string) (*UserSubscriptions2Id, error) { + parser := resourceids.NewParserFromResourceIdType(&UserSubscriptions2Id{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UserSubscriptions2Id{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *UserSubscriptions2Id) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.UserId, ok = input.Parsed["userId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "userId", input) + } + + if id.SubscriptionName, ok = input.Parsed["subscriptionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionName", input) + } + + return nil +} + +// ValidateUserSubscriptions2ID checks that 'input' can be parsed as a User Subscriptions 2 ID +func ValidateUserSubscriptions2ID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseUserSubscriptions2ID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted User Subscriptions 2 ID +func (id UserSubscriptions2Id) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/users/%s/subscriptions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.UserId, id.SubscriptionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this User Subscriptions 2 ID +func (id UserSubscriptions2Id) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticUsers", "users", "users"), + resourceids.UserSpecifiedSegment("userId", "userIdValue"), + resourceids.StaticSegment("staticSubscriptions2", "subscriptions", "subscriptions"), + resourceids.UserSpecifiedSegment("subscriptionName", "subscriptionValue"), + } +} + +// String returns a human-readable description of this User Subscriptions 2 ID +func (id UserSubscriptions2Id) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("User: %q", id.UserId), + fmt.Sprintf("Subscription Name: %q", id.SubscriptionName), + } + return fmt.Sprintf("User Subscriptions 2 (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/id_usersubscriptions2_test.go b/resource-manager/apimanagement/2024-05-01/subscription/id_usersubscriptions2_test.go new file mode 100644 index 00000000000..92b158f5547 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/id_usersubscriptions2_test.go @@ -0,0 +1,372 @@ +package subscription + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &UserSubscriptions2Id{} + +func TestNewUserSubscriptions2ID(t *testing.T) { + id := NewUserSubscriptions2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue", "subscriptionValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.UserId != "userIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'UserId'", id.UserId, "userIdValue") + } + + if id.SubscriptionName != "subscriptionValue" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionName'", id.SubscriptionName, "subscriptionValue") + } +} + +func TestFormatUserSubscriptions2ID(t *testing.T) { + actual := NewUserSubscriptions2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue", "subscriptionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue/subscriptions/subscriptionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseUserSubscriptions2ID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UserSubscriptions2Id + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue/subscriptions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue/subscriptions/subscriptionValue", + Expected: &UserSubscriptions2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + UserId: "userIdValue", + SubscriptionName: "subscriptionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue/subscriptions/subscriptionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUserSubscriptions2ID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.UserId != v.Expected.UserId { + t.Fatalf("Expected %q but got %q for UserId", v.Expected.UserId, actual.UserId) + } + + if actual.SubscriptionName != v.Expected.SubscriptionName { + t.Fatalf("Expected %q but got %q for SubscriptionName", v.Expected.SubscriptionName, actual.SubscriptionName) + } + + } +} + +func TestParseUserSubscriptions2IDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UserSubscriptions2Id + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs/uSeRiDvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs/uSeRiDvAlUe/sUbScRiPtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue/subscriptions/subscriptionValue", + Expected: &UserSubscriptions2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + UserId: "userIdValue", + SubscriptionName: "subscriptionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue/subscriptions/subscriptionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs/uSeRiDvAlUe/sUbScRiPtIoNs/sUbScRiPtIoNvAlUe", + Expected: &UserSubscriptions2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + UserId: "uSeRiDvAlUe", + SubscriptionName: "sUbScRiPtIoNvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs/uSeRiDvAlUe/sUbScRiPtIoNs/sUbScRiPtIoNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUserSubscriptions2IDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.UserId != v.Expected.UserId { + t.Fatalf("Expected %q but got %q for UserId", v.Expected.UserId, actual.UserId) + } + + if actual.SubscriptionName != v.Expected.SubscriptionName { + t.Fatalf("Expected %q but got %q for SubscriptionName", v.Expected.SubscriptionName, actual.SubscriptionName) + } + + } +} + +func TestSegmentsForUserSubscriptions2Id(t *testing.T) { + segments := UserSubscriptions2Id{}.Segments() + if len(segments) == 0 { + t.Fatalf("UserSubscriptions2Id has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/id_workspace.go b/resource-manager/apimanagement/2024-05-01/subscription/id_workspace.go new file mode 100644 index 00000000000..f2e1bd584a2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/id_workspace.go @@ -0,0 +1,139 @@ +package subscription + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/id_workspace_test.go b/resource-manager/apimanagement/2024-05-01/subscription/id_workspace_test.go new file mode 100644 index 00000000000..2912e342ed8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/id_workspace_test.go @@ -0,0 +1,327 @@ +package subscription + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/id_workspacesubscriptions2.go b/resource-manager/apimanagement/2024-05-01/subscription/id_workspacesubscriptions2.go new file mode 100644 index 00000000000..5ec25c56a27 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/id_workspacesubscriptions2.go @@ -0,0 +1,148 @@ +package subscription + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceSubscriptions2Id{}) +} + +var _ resourceids.ResourceId = &WorkspaceSubscriptions2Id{} + +// WorkspaceSubscriptions2Id is a struct representing the Resource ID for a Workspace Subscriptions 2 +type WorkspaceSubscriptions2Id struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + SubscriptionName string +} + +// NewWorkspaceSubscriptions2ID returns a new WorkspaceSubscriptions2Id struct +func NewWorkspaceSubscriptions2ID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, subscriptionName string) WorkspaceSubscriptions2Id { + return WorkspaceSubscriptions2Id{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + SubscriptionName: subscriptionName, + } +} + +// ParseWorkspaceSubscriptions2ID parses 'input' into a WorkspaceSubscriptions2Id +func ParseWorkspaceSubscriptions2ID(input string) (*WorkspaceSubscriptions2Id, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceSubscriptions2Id{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceSubscriptions2Id{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceSubscriptions2IDInsensitively parses 'input' case-insensitively into a WorkspaceSubscriptions2Id +// note: this method should only be used for API response data and not user input +func ParseWorkspaceSubscriptions2IDInsensitively(input string) (*WorkspaceSubscriptions2Id, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceSubscriptions2Id{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceSubscriptions2Id{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceSubscriptions2Id) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.SubscriptionName, ok = input.Parsed["subscriptionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionName", input) + } + + return nil +} + +// ValidateWorkspaceSubscriptions2ID checks that 'input' can be parsed as a Workspace Subscriptions 2 ID +func ValidateWorkspaceSubscriptions2ID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceSubscriptions2ID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Subscriptions 2 ID +func (id WorkspaceSubscriptions2Id) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/subscriptions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.SubscriptionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Subscriptions 2 ID +func (id WorkspaceSubscriptions2Id) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticSubscriptions2", "subscriptions", "subscriptions"), + resourceids.UserSpecifiedSegment("subscriptionName", "subscriptionValue"), + } +} + +// String returns a human-readable description of this Workspace Subscriptions 2 ID +func (id WorkspaceSubscriptions2Id) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Subscription Name: %q", id.SubscriptionName), + } + return fmt.Sprintf("Workspace Subscriptions 2 (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/id_workspacesubscriptions2_test.go b/resource-manager/apimanagement/2024-05-01/subscription/id_workspacesubscriptions2_test.go new file mode 100644 index 00000000000..5eb28a14767 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/id_workspacesubscriptions2_test.go @@ -0,0 +1,372 @@ +package subscription + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceSubscriptions2Id{} + +func TestNewWorkspaceSubscriptions2ID(t *testing.T) { + id := NewWorkspaceSubscriptions2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "subscriptionValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.SubscriptionName != "subscriptionValue" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionName'", id.SubscriptionName, "subscriptionValue") + } +} + +func TestFormatWorkspaceSubscriptions2ID(t *testing.T) { + actual := NewWorkspaceSubscriptions2ID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "subscriptionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/subscriptions/subscriptionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceSubscriptions2ID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceSubscriptions2Id + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/subscriptions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/subscriptions/subscriptionValue", + Expected: &WorkspaceSubscriptions2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + SubscriptionName: "subscriptionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/subscriptions/subscriptionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceSubscriptions2ID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.SubscriptionName != v.Expected.SubscriptionName { + t.Fatalf("Expected %q but got %q for SubscriptionName", v.Expected.SubscriptionName, actual.SubscriptionName) + } + + } +} + +func TestParseWorkspaceSubscriptions2IDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceSubscriptions2Id + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/sUbScRiPtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/subscriptions/subscriptionValue", + Expected: &WorkspaceSubscriptions2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + SubscriptionName: "subscriptionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/subscriptions/subscriptionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/sUbScRiPtIoNs/sUbScRiPtIoNvAlUe", + Expected: &WorkspaceSubscriptions2Id{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + SubscriptionName: "sUbScRiPtIoNvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/sUbScRiPtIoNs/sUbScRiPtIoNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceSubscriptions2IDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.SubscriptionName != v.Expected.SubscriptionName { + t.Fatalf("Expected %q but got %q for SubscriptionName", v.Expected.SubscriptionName, actual.SubscriptionName) + } + + } +} + +func TestSegmentsForWorkspaceSubscriptions2Id(t *testing.T) { + segments := WorkspaceSubscriptions2Id{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceSubscriptions2Id has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/subscription/method_createorupdate.go new file mode 100644 index 00000000000..84f04d880d0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/method_createorupdate.go @@ -0,0 +1,95 @@ +package subscription + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SubscriptionContract +} + +type CreateOrUpdateOperationOptions struct { + AppType *AppType + IfMatch *string + Notify *bool +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.AppType != nil { + out.Append("appType", fmt.Sprintf("%v", *o.AppType)) + } + if o.Notify != nil { + out.Append("notify", fmt.Sprintf("%v", *o.Notify)) + } + return &out +} + +// CreateOrUpdate ... +func (c SubscriptionClient) CreateOrUpdate(ctx context.Context, id Subscriptions2Id, input SubscriptionCreateParameters, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 SubscriptionContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/method_delete.go b/resource-manager/apimanagement/2024-05-01/subscription/method_delete.go new file mode 100644 index 00000000000..e3c31885a75 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/method_delete.go @@ -0,0 +1,76 @@ +package subscription + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c SubscriptionClient) Delete(ctx context.Context, id Subscriptions2Id, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/method_get.go b/resource-manager/apimanagement/2024-05-01/subscription/method_get.go new file mode 100644 index 00000000000..9a57c676f8b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/method_get.go @@ -0,0 +1,54 @@ +package subscription + +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 *SubscriptionContract +} + +// Get ... +func (c SubscriptionClient) Get(ctx context.Context, id Subscriptions2Id) (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 SubscriptionContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/subscription/method_getentitytag.go new file mode 100644 index 00000000000..70173b87ce1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/method_getentitytag.go @@ -0,0 +1,46 @@ +package subscription + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c SubscriptionClient) GetEntityTag(ctx context.Context, id Subscriptions2Id) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/method_list.go b/resource-manager/apimanagement/2024-05-01/subscription/method_list.go new file mode 100644 index 00000000000..2e9d96e0473 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/method_list.go @@ -0,0 +1,141 @@ +package subscription + +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 *[]SubscriptionContract +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []SubscriptionContract +} + +type ListOperationOptions struct { + Filter *string + Skip *int64 + 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.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c SubscriptionClient) List(ctx context.Context, id ServiceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/subscriptions", 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 *[]SubscriptionContract `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 SubscriptionClient) ListComplete(ctx context.Context, id ServiceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, SubscriptionContractOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SubscriptionClient) ListCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListOperationOptions, predicate SubscriptionContractOperationPredicate) (result ListCompleteResult, err error) { + items := make([]SubscriptionContract, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/method_listsecrets.go b/resource-manager/apimanagement/2024-05-01/subscription/method_listsecrets.go new file mode 100644 index 00000000000..579b90282a8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/method_listsecrets.go @@ -0,0 +1,55 @@ +package subscription + +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 ListSecretsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SubscriptionKeysContract +} + +// ListSecrets ... +func (c SubscriptionClient) ListSecrets(ctx context.Context, id Subscriptions2Id) (result ListSecretsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listSecrets", 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 SubscriptionKeysContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/method_regenerateprimarykey.go b/resource-manager/apimanagement/2024-05-01/subscription/method_regenerateprimarykey.go new file mode 100644 index 00000000000..d2ae52bbb7c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/method_regenerateprimarykey.go @@ -0,0 +1,47 @@ +package subscription + +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 RegeneratePrimaryKeyOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// RegeneratePrimaryKey ... +func (c SubscriptionClient) RegeneratePrimaryKey(ctx context.Context, id Subscriptions2Id) (result RegeneratePrimaryKeyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/regeneratePrimaryKey", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/method_regeneratesecondarykey.go b/resource-manager/apimanagement/2024-05-01/subscription/method_regeneratesecondarykey.go new file mode 100644 index 00000000000..7e3998ced00 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/method_regeneratesecondarykey.go @@ -0,0 +1,47 @@ +package subscription + +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 RegenerateSecondaryKeyOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// RegenerateSecondaryKey ... +func (c SubscriptionClient) RegenerateSecondaryKey(ctx context.Context, id Subscriptions2Id) (result RegenerateSecondaryKeyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/regenerateSecondaryKey", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/method_update.go b/resource-manager/apimanagement/2024-05-01/subscription/method_update.go new file mode 100644 index 00000000000..635071e41ca --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/method_update.go @@ -0,0 +1,94 @@ +package subscription + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SubscriptionContract +} + +type UpdateOperationOptions struct { + AppType *AppType + IfMatch *string + Notify *bool +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.AppType != nil { + out.Append("appType", fmt.Sprintf("%v", *o.AppType)) + } + if o.Notify != nil { + out.Append("notify", fmt.Sprintf("%v", *o.Notify)) + } + return &out +} + +// Update ... +func (c SubscriptionClient) Update(ctx context.Context, id Subscriptions2Id, input SubscriptionUpdateParameters, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 SubscriptionContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/method_usersubscriptionget.go b/resource-manager/apimanagement/2024-05-01/subscription/method_usersubscriptionget.go new file mode 100644 index 00000000000..4323e0a04c6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/method_usersubscriptionget.go @@ -0,0 +1,54 @@ +package subscription + +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 UserSubscriptionGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SubscriptionContract +} + +// UserSubscriptionGet ... +func (c SubscriptionClient) UserSubscriptionGet(ctx context.Context, id UserSubscriptions2Id) (result UserSubscriptionGetOperationResponse, 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 SubscriptionContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptioncreateorupdate.go b/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptioncreateorupdate.go new file mode 100644 index 00000000000..9c4c3b06ccb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptioncreateorupdate.go @@ -0,0 +1,95 @@ +package subscription + +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 WorkspaceSubscriptionCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SubscriptionContract +} + +type WorkspaceSubscriptionCreateOrUpdateOperationOptions struct { + AppType *AppType + IfMatch *string + Notify *bool +} + +func DefaultWorkspaceSubscriptionCreateOrUpdateOperationOptions() WorkspaceSubscriptionCreateOrUpdateOperationOptions { + return WorkspaceSubscriptionCreateOrUpdateOperationOptions{} +} + +func (o WorkspaceSubscriptionCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceSubscriptionCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceSubscriptionCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.AppType != nil { + out.Append("appType", fmt.Sprintf("%v", *o.AppType)) + } + if o.Notify != nil { + out.Append("notify", fmt.Sprintf("%v", *o.Notify)) + } + return &out +} + +// WorkspaceSubscriptionCreateOrUpdate ... +func (c SubscriptionClient) WorkspaceSubscriptionCreateOrUpdate(ctx context.Context, id WorkspaceSubscriptions2Id, input SubscriptionCreateParameters, options WorkspaceSubscriptionCreateOrUpdateOperationOptions) (result WorkspaceSubscriptionCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 SubscriptionContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptiondelete.go b/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptiondelete.go new file mode 100644 index 00000000000..ae93f99c979 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptiondelete.go @@ -0,0 +1,76 @@ +package subscription + +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 WorkspaceSubscriptionDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type WorkspaceSubscriptionDeleteOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceSubscriptionDeleteOperationOptions() WorkspaceSubscriptionDeleteOperationOptions { + return WorkspaceSubscriptionDeleteOperationOptions{} +} + +func (o WorkspaceSubscriptionDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceSubscriptionDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceSubscriptionDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceSubscriptionDelete ... +func (c SubscriptionClient) WorkspaceSubscriptionDelete(ctx context.Context, id WorkspaceSubscriptions2Id, options WorkspaceSubscriptionDeleteOperationOptions) (result WorkspaceSubscriptionDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptionget.go b/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptionget.go new file mode 100644 index 00000000000..37ea5ebe516 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptionget.go @@ -0,0 +1,54 @@ +package subscription + +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 WorkspaceSubscriptionGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SubscriptionContract +} + +// WorkspaceSubscriptionGet ... +func (c SubscriptionClient) WorkspaceSubscriptionGet(ctx context.Context, id WorkspaceSubscriptions2Id) (result WorkspaceSubscriptionGetOperationResponse, 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 SubscriptionContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptiongetentitytag.go b/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptiongetentitytag.go new file mode 100644 index 00000000000..4eb6ac80a13 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptiongetentitytag.go @@ -0,0 +1,46 @@ +package subscription + +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 WorkspaceSubscriptionGetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceSubscriptionGetEntityTag ... +func (c SubscriptionClient) WorkspaceSubscriptionGetEntityTag(ctx context.Context, id WorkspaceSubscriptions2Id) (result WorkspaceSubscriptionGetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptionlist.go b/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptionlist.go new file mode 100644 index 00000000000..ae68c703393 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptionlist.go @@ -0,0 +1,141 @@ +package subscription + +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 WorkspaceSubscriptionListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SubscriptionContract +} + +type WorkspaceSubscriptionListCompleteResult struct { + LatestHttpResponse *http.Response + Items []SubscriptionContract +} + +type WorkspaceSubscriptionListOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultWorkspaceSubscriptionListOperationOptions() WorkspaceSubscriptionListOperationOptions { + return WorkspaceSubscriptionListOperationOptions{} +} + +func (o WorkspaceSubscriptionListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceSubscriptionListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceSubscriptionListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspaceSubscriptionListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceSubscriptionListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceSubscriptionList ... +func (c SubscriptionClient) WorkspaceSubscriptionList(ctx context.Context, id WorkspaceId, options WorkspaceSubscriptionListOperationOptions) (result WorkspaceSubscriptionListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspaceSubscriptionListCustomPager{}, + Path: fmt.Sprintf("%s/subscriptions", 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 *[]SubscriptionContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceSubscriptionListComplete retrieves all the results into a single object +func (c SubscriptionClient) WorkspaceSubscriptionListComplete(ctx context.Context, id WorkspaceId, options WorkspaceSubscriptionListOperationOptions) (WorkspaceSubscriptionListCompleteResult, error) { + return c.WorkspaceSubscriptionListCompleteMatchingPredicate(ctx, id, options, SubscriptionContractOperationPredicate{}) +} + +// WorkspaceSubscriptionListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SubscriptionClient) WorkspaceSubscriptionListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options WorkspaceSubscriptionListOperationOptions, predicate SubscriptionContractOperationPredicate) (result WorkspaceSubscriptionListCompleteResult, err error) { + items := make([]SubscriptionContract, 0) + + resp, err := c.WorkspaceSubscriptionList(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceSubscriptionListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptionlistsecrets.go b/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptionlistsecrets.go new file mode 100644 index 00000000000..5aaf63656bd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptionlistsecrets.go @@ -0,0 +1,55 @@ +package subscription + +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 WorkspaceSubscriptionListSecretsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SubscriptionKeysContract +} + +// WorkspaceSubscriptionListSecrets ... +func (c SubscriptionClient) WorkspaceSubscriptionListSecrets(ctx context.Context, id WorkspaceSubscriptions2Id) (result WorkspaceSubscriptionListSecretsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listSecrets", 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 SubscriptionKeysContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptionregenerateprimarykey.go b/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptionregenerateprimarykey.go new file mode 100644 index 00000000000..84d769c707e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptionregenerateprimarykey.go @@ -0,0 +1,47 @@ +package subscription + +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 WorkspaceSubscriptionRegeneratePrimaryKeyOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceSubscriptionRegeneratePrimaryKey ... +func (c SubscriptionClient) WorkspaceSubscriptionRegeneratePrimaryKey(ctx context.Context, id WorkspaceSubscriptions2Id) (result WorkspaceSubscriptionRegeneratePrimaryKeyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/regeneratePrimaryKey", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptionregeneratesecondarykey.go b/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptionregeneratesecondarykey.go new file mode 100644 index 00000000000..553959c4636 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptionregeneratesecondarykey.go @@ -0,0 +1,47 @@ +package subscription + +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 WorkspaceSubscriptionRegenerateSecondaryKeyOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceSubscriptionRegenerateSecondaryKey ... +func (c SubscriptionClient) WorkspaceSubscriptionRegenerateSecondaryKey(ctx context.Context, id WorkspaceSubscriptions2Id) (result WorkspaceSubscriptionRegenerateSecondaryKeyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/regenerateSecondaryKey", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptionupdate.go b/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptionupdate.go new file mode 100644 index 00000000000..e8866e97051 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/method_workspacesubscriptionupdate.go @@ -0,0 +1,94 @@ +package subscription + +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 WorkspaceSubscriptionUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SubscriptionContract +} + +type WorkspaceSubscriptionUpdateOperationOptions struct { + AppType *AppType + IfMatch *string + Notify *bool +} + +func DefaultWorkspaceSubscriptionUpdateOperationOptions() WorkspaceSubscriptionUpdateOperationOptions { + return WorkspaceSubscriptionUpdateOperationOptions{} +} + +func (o WorkspaceSubscriptionUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceSubscriptionUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceSubscriptionUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.AppType != nil { + out.Append("appType", fmt.Sprintf("%v", *o.AppType)) + } + if o.Notify != nil { + out.Append("notify", fmt.Sprintf("%v", *o.Notify)) + } + return &out +} + +// WorkspaceSubscriptionUpdate ... +func (c SubscriptionClient) WorkspaceSubscriptionUpdate(ctx context.Context, id WorkspaceSubscriptions2Id, input SubscriptionUpdateParameters, options WorkspaceSubscriptionUpdateOperationOptions) (result WorkspaceSubscriptionUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 SubscriptionContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/model_subscriptioncontract.go b/resource-manager/apimanagement/2024-05-01/subscription/model_subscriptioncontract.go new file mode 100644 index 00000000000..ab731cdb9cb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/model_subscriptioncontract.go @@ -0,0 +1,11 @@ +package subscription + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SubscriptionContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/model_subscriptioncontractproperties.go b/resource-manager/apimanagement/2024-05-01/subscription/model_subscriptioncontractproperties.go new file mode 100644 index 00000000000..dfe4f8584c0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/model_subscriptioncontractproperties.go @@ -0,0 +1,86 @@ +package subscription + +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 SubscriptionContractProperties struct { + AllowTracing *bool `json:"allowTracing,omitempty"` + CreatedDate *string `json:"createdDate,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + EndDate *string `json:"endDate,omitempty"` + ExpirationDate *string `json:"expirationDate,omitempty"` + NotificationDate *string `json:"notificationDate,omitempty"` + OwnerId *string `json:"ownerId,omitempty"` + PrimaryKey *string `json:"primaryKey,omitempty"` + Scope string `json:"scope"` + SecondaryKey *string `json:"secondaryKey,omitempty"` + StartDate *string `json:"startDate,omitempty"` + State SubscriptionState `json:"state"` + StateComment *string `json:"stateComment,omitempty"` +} + +func (o *SubscriptionContractProperties) GetCreatedDateAsTime() (*time.Time, error) { + if o.CreatedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SubscriptionContractProperties) SetCreatedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedDate = &formatted +} + +func (o *SubscriptionContractProperties) GetEndDateAsTime() (*time.Time, error) { + if o.EndDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SubscriptionContractProperties) SetEndDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndDate = &formatted +} + +func (o *SubscriptionContractProperties) GetExpirationDateAsTime() (*time.Time, error) { + if o.ExpirationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpirationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SubscriptionContractProperties) SetExpirationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpirationDate = &formatted +} + +func (o *SubscriptionContractProperties) GetNotificationDateAsTime() (*time.Time, error) { + if o.NotificationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.NotificationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SubscriptionContractProperties) SetNotificationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.NotificationDate = &formatted +} + +func (o *SubscriptionContractProperties) GetStartDateAsTime() (*time.Time, error) { + if o.StartDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SubscriptionContractProperties) SetStartDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartDate = &formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/model_subscriptioncreateparameterproperties.go b/resource-manager/apimanagement/2024-05-01/subscription/model_subscriptioncreateparameterproperties.go new file mode 100644 index 00000000000..2ac36f98e30 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/model_subscriptioncreateparameterproperties.go @@ -0,0 +1,14 @@ +package subscription + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionCreateParameterProperties struct { + AllowTracing *bool `json:"allowTracing,omitempty"` + DisplayName string `json:"displayName"` + OwnerId *string `json:"ownerId,omitempty"` + PrimaryKey *string `json:"primaryKey,omitempty"` + Scope string `json:"scope"` + SecondaryKey *string `json:"secondaryKey,omitempty"` + State *SubscriptionState `json:"state,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/model_subscriptioncreateparameters.go b/resource-manager/apimanagement/2024-05-01/subscription/model_subscriptioncreateparameters.go new file mode 100644 index 00000000000..a2f57c3b4a4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/model_subscriptioncreateparameters.go @@ -0,0 +1,8 @@ +package subscription + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionCreateParameters struct { + Properties *SubscriptionCreateParameterProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/model_subscriptionkeyscontract.go b/resource-manager/apimanagement/2024-05-01/subscription/model_subscriptionkeyscontract.go new file mode 100644 index 00000000000..93de07ed127 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/model_subscriptionkeyscontract.go @@ -0,0 +1,9 @@ +package subscription + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionKeysContract struct { + PrimaryKey *string `json:"primaryKey,omitempty"` + SecondaryKey *string `json:"secondaryKey,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/model_subscriptionupdateparameterproperties.go b/resource-manager/apimanagement/2024-05-01/subscription/model_subscriptionupdateparameterproperties.go new file mode 100644 index 00000000000..7e4602c3021 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/model_subscriptionupdateparameterproperties.go @@ -0,0 +1,34 @@ +package subscription + +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 SubscriptionUpdateParameterProperties struct { + AllowTracing *bool `json:"allowTracing,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + ExpirationDate *string `json:"expirationDate,omitempty"` + OwnerId *string `json:"ownerId,omitempty"` + PrimaryKey *string `json:"primaryKey,omitempty"` + Scope *string `json:"scope,omitempty"` + SecondaryKey *string `json:"secondaryKey,omitempty"` + State *SubscriptionState `json:"state,omitempty"` + StateComment *string `json:"stateComment,omitempty"` +} + +func (o *SubscriptionUpdateParameterProperties) GetExpirationDateAsTime() (*time.Time, error) { + if o.ExpirationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpirationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SubscriptionUpdateParameterProperties) SetExpirationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpirationDate = &formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/model_subscriptionupdateparameters.go b/resource-manager/apimanagement/2024-05-01/subscription/model_subscriptionupdateparameters.go new file mode 100644 index 00000000000..e4a2d381d4b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/model_subscriptionupdateparameters.go @@ -0,0 +1,8 @@ +package subscription + +// 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 *SubscriptionUpdateParameterProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/subscription/predicates.go b/resource-manager/apimanagement/2024-05-01/subscription/predicates.go new file mode 100644 index 00000000000..71fb75412ad --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/predicates.go @@ -0,0 +1,27 @@ +package subscription + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SubscriptionContractOperationPredicate) Matches(input SubscriptionContract) 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/apimanagement/2024-05-01/subscription/version.go b/resource-manager/apimanagement/2024-05-01/subscription/version.go new file mode 100644 index 00000000000..433289b9fa1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/subscription/version.go @@ -0,0 +1,12 @@ +package subscription + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/subscription/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/README.md b/resource-manager/apimanagement/2024-05-01/tag/README.md new file mode 100644 index 00000000000..519b9c18577 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/README.md @@ -0,0 +1,234 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tag` Documentation + +The `tag` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tag" +``` + + +### Client Initialization + +```go +client := tag.NewTagClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TagClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := tag.NewTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue") + +payload := tag.TagCreateUpdateParameters{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, tag.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagClient.Delete` + +```go +ctx := context.TODO() +id := tag.NewTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue") + +read, err := client.Delete(ctx, id, tag.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagClient.Get` + +```go +ctx := context.TODO() +id := tag.NewTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue") + +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: `TagClient.GetEntityState` + +```go +ctx := context.TODO() +id := tag.NewTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue") + +read, err := client.GetEntityState(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagClient.ListByService` + +```go +ctx := context.TODO() +id := tag.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, tag.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, tag.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `TagClient.Update` + +```go +ctx := context.TODO() +id := tag.NewTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue") + +payload := tag.TagCreateUpdateParameters{ + // ... +} + + +read, err := client.Update(ctx, id, payload, tag.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagClient.WorkspaceTagCreateOrUpdate` + +```go +ctx := context.TODO() +id := tag.NewWorkspaceTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue") + +payload := tag.TagCreateUpdateParameters{ + // ... +} + + +read, err := client.WorkspaceTagCreateOrUpdate(ctx, id, payload, tag.DefaultWorkspaceTagCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagClient.WorkspaceTagDelete` + +```go +ctx := context.TODO() +id := tag.NewWorkspaceTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue") + +read, err := client.WorkspaceTagDelete(ctx, id, tag.DefaultWorkspaceTagDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagClient.WorkspaceTagGet` + +```go +ctx := context.TODO() +id := tag.NewWorkspaceTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue") + +read, err := client.WorkspaceTagGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagClient.WorkspaceTagGetEntityState` + +```go +ctx := context.TODO() +id := tag.NewWorkspaceTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue") + +read, err := client.WorkspaceTagGetEntityState(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagClient.WorkspaceTagListByService` + +```go +ctx := context.TODO() +id := tag.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +// alternatively `client.WorkspaceTagListByService(ctx, id, tag.DefaultWorkspaceTagListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.WorkspaceTagListByServiceComplete(ctx, id, tag.DefaultWorkspaceTagListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `TagClient.WorkspaceTagUpdate` + +```go +ctx := context.TODO() +id := tag.NewWorkspaceTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue") + +payload := tag.TagCreateUpdateParameters{ + // ... +} + + +read, err := client.WorkspaceTagUpdate(ctx, id, payload, tag.DefaultWorkspaceTagUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/tag/client.go b/resource-manager/apimanagement/2024-05-01/tag/client.go new file mode 100644 index 00000000000..e97e5adc95e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/client.go @@ -0,0 +1,26 @@ +package tag + +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 TagClient struct { + Client *resourcemanager.Client +} + +func NewTagClientWithBaseURI(sdkApi sdkEnv.Api) (*TagClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "tag", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TagClient: %+v", err) + } + + return &TagClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/id_service.go b/resource-manager/apimanagement/2024-05-01/tag/id_service.go new file mode 100644 index 00000000000..c2136f64b3e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/id_service.go @@ -0,0 +1,130 @@ +package tag + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/id_service_test.go b/resource-manager/apimanagement/2024-05-01/tag/id_service_test.go new file mode 100644 index 00000000000..48905d26dd6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/id_service_test.go @@ -0,0 +1,282 @@ +package tag + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/id_tag.go b/resource-manager/apimanagement/2024-05-01/tag/id_tag.go new file mode 100644 index 00000000000..568503a639c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/id_tag.go @@ -0,0 +1,139 @@ +package tag + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TagId{}) +} + +var _ resourceids.ResourceId = &TagId{} + +// TagId is a struct representing the Resource ID for a Tag +type TagId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + TagId string +} + +// NewTagID returns a new TagId struct +func NewTagID(subscriptionId string, resourceGroupName string, serviceName string, tagId string) TagId { + return TagId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + TagId: tagId, + } +} + +// ParseTagID parses 'input' into a TagId +func ParseTagID(input string) (*TagId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTagIDInsensitively parses 'input' case-insensitively into a TagId +// note: this method should only be used for API response data and not user input +func ParseTagIDInsensitively(input string) (*TagId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TagId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.TagId, ok = input.Parsed["tagId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagId", input) + } + + return nil +} + +// ValidateTagID checks that 'input' can be parsed as a Tag ID +func ValidateTagID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseTagID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Tag ID +func (id TagId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/tags/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.TagId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Tag ID +func (id TagId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticTags", "tags", "tags"), + resourceids.UserSpecifiedSegment("tagId", "tagIdValue"), + } +} + +// String returns a human-readable description of this Tag ID +func (id TagId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Tag: %q", id.TagId), + } + return fmt.Sprintf("Tag (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/id_tag_test.go b/resource-manager/apimanagement/2024-05-01/tag/id_tag_test.go new file mode 100644 index 00000000000..dc5cb518049 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/id_tag_test.go @@ -0,0 +1,327 @@ +package tag + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TagId{} + +func TestNewTagID(t *testing.T) { + id := NewTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.TagId != "tagIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'TagId'", id.TagId, "tagIdValue") + } +} + +func TestFormatTagID(t *testing.T) { + actual := NewTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTagID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue", + Expected: &TagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + TagId: "tagIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + } +} + +func TestParseTagIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue", + Expected: &TagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + TagId: "tagIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS/tAgIdVaLuE", + Expected: &TagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + TagId: "tAgIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS/tAgIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + } +} + +func TestSegmentsForTagId(t *testing.T) { + segments := TagId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TagId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/id_workspace.go b/resource-manager/apimanagement/2024-05-01/tag/id_workspace.go new file mode 100644 index 00000000000..3028a0894dc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/id_workspace.go @@ -0,0 +1,139 @@ +package tag + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/id_workspace_test.go b/resource-manager/apimanagement/2024-05-01/tag/id_workspace_test.go new file mode 100644 index 00000000000..cefe5975bfd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/id_workspace_test.go @@ -0,0 +1,327 @@ +package tag + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/id_workspacetag.go b/resource-manager/apimanagement/2024-05-01/tag/id_workspacetag.go new file mode 100644 index 00000000000..22e3dc2edb3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/id_workspacetag.go @@ -0,0 +1,148 @@ +package tag + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceTagId{}) +} + +var _ resourceids.ResourceId = &WorkspaceTagId{} + +// WorkspaceTagId is a struct representing the Resource ID for a Workspace Tag +type WorkspaceTagId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + TagId string +} + +// NewWorkspaceTagID returns a new WorkspaceTagId struct +func NewWorkspaceTagID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, tagId string) WorkspaceTagId { + return WorkspaceTagId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + TagId: tagId, + } +} + +// ParseWorkspaceTagID parses 'input' into a WorkspaceTagId +func ParseWorkspaceTagID(input string) (*WorkspaceTagId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceTagId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceTagId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceTagIDInsensitively parses 'input' case-insensitively into a WorkspaceTagId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceTagIDInsensitively(input string) (*WorkspaceTagId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceTagId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceTagId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceTagId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.TagId, ok = input.Parsed["tagId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagId", input) + } + + return nil +} + +// ValidateWorkspaceTagID checks that 'input' can be parsed as a Workspace Tag ID +func ValidateWorkspaceTagID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceTagID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Tag ID +func (id WorkspaceTagId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/tags/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.TagId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Tag ID +func (id WorkspaceTagId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticTags", "tags", "tags"), + resourceids.UserSpecifiedSegment("tagId", "tagIdValue"), + } +} + +// String returns a human-readable description of this Workspace Tag ID +func (id WorkspaceTagId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Tag: %q", id.TagId), + } + return fmt.Sprintf("Workspace Tag (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/id_workspacetag_test.go b/resource-manager/apimanagement/2024-05-01/tag/id_workspacetag_test.go new file mode 100644 index 00000000000..123d1e051c6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/id_workspacetag_test.go @@ -0,0 +1,372 @@ +package tag + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceTagId{} + +func TestNewWorkspaceTagID(t *testing.T) { + id := NewWorkspaceTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.TagId != "tagIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'TagId'", id.TagId, "tagIdValue") + } +} + +func TestFormatWorkspaceTagID(t *testing.T) { + actual := NewWorkspaceTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceTagID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceTagId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue", + Expected: &WorkspaceTagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + TagId: "tagIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceTagID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + } +} + +func TestParseWorkspaceTagIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceTagId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue", + Expected: &WorkspaceTagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + TagId: "tagIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS/tAgIdVaLuE", + Expected: &WorkspaceTagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + TagId: "tAgIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS/tAgIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceTagIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + } +} + +func TestSegmentsForWorkspaceTagId(t *testing.T) { + segments := WorkspaceTagId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceTagId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/tag/method_createorupdate.go new file mode 100644 index 00000000000..9494659a794 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/method_createorupdate.go @@ -0,0 +1,88 @@ +package tag + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TagContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c TagClient) CreateOrUpdate(ctx context.Context, id TagId, input TagCreateUpdateParameters, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 TagContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/method_delete.go b/resource-manager/apimanagement/2024-05-01/tag/method_delete.go new file mode 100644 index 00000000000..83335d794bd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/method_delete.go @@ -0,0 +1,76 @@ +package tag + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c TagClient) Delete(ctx context.Context, id TagId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/method_get.go b/resource-manager/apimanagement/2024-05-01/tag/method_get.go new file mode 100644 index 00000000000..8395e2cb1b1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/method_get.go @@ -0,0 +1,54 @@ +package tag + +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 *TagContract +} + +// Get ... +func (c TagClient) Get(ctx context.Context, id TagId) (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 TagContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/method_getentitystate.go b/resource-manager/apimanagement/2024-05-01/tag/method_getentitystate.go new file mode 100644 index 00000000000..b56c0026a99 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/method_getentitystate.go @@ -0,0 +1,46 @@ +package tag + +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 GetEntityStateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityState ... +func (c TagClient) GetEntityState(ctx context.Context, id TagId) (result GetEntityStateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/tag/method_listbyservice.go new file mode 100644 index 00000000000..efb001aaa9c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/method_listbyservice.go @@ -0,0 +1,145 @@ +package tag + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TagContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []TagContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Scope *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Scope != nil { + out.Append("scope", fmt.Sprintf("%v", *o.Scope)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c TagClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/tags", 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 *[]TagContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c TagClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, TagContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TagClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate TagContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]TagContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/method_update.go b/resource-manager/apimanagement/2024-05-01/tag/method_update.go new file mode 100644 index 00000000000..8ee0391b4d4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/method_update.go @@ -0,0 +1,87 @@ +package tag + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TagContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c TagClient) Update(ctx context.Context, id TagId, input TagCreateUpdateParameters, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 TagContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/method_workspacetagcreateorupdate.go b/resource-manager/apimanagement/2024-05-01/tag/method_workspacetagcreateorupdate.go new file mode 100644 index 00000000000..43dd91a0327 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/method_workspacetagcreateorupdate.go @@ -0,0 +1,88 @@ +package tag + +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 WorkspaceTagCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TagContract +} + +type WorkspaceTagCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceTagCreateOrUpdateOperationOptions() WorkspaceTagCreateOrUpdateOperationOptions { + return WorkspaceTagCreateOrUpdateOperationOptions{} +} + +func (o WorkspaceTagCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceTagCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceTagCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceTagCreateOrUpdate ... +func (c TagClient) WorkspaceTagCreateOrUpdate(ctx context.Context, id WorkspaceTagId, input TagCreateUpdateParameters, options WorkspaceTagCreateOrUpdateOperationOptions) (result WorkspaceTagCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 TagContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/method_workspacetagdelete.go b/resource-manager/apimanagement/2024-05-01/tag/method_workspacetagdelete.go new file mode 100644 index 00000000000..c702a5f54dc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/method_workspacetagdelete.go @@ -0,0 +1,76 @@ +package tag + +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 WorkspaceTagDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type WorkspaceTagDeleteOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceTagDeleteOperationOptions() WorkspaceTagDeleteOperationOptions { + return WorkspaceTagDeleteOperationOptions{} +} + +func (o WorkspaceTagDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceTagDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceTagDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceTagDelete ... +func (c TagClient) WorkspaceTagDelete(ctx context.Context, id WorkspaceTagId, options WorkspaceTagDeleteOperationOptions) (result WorkspaceTagDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/method_workspacetagget.go b/resource-manager/apimanagement/2024-05-01/tag/method_workspacetagget.go new file mode 100644 index 00000000000..70647072c3e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/method_workspacetagget.go @@ -0,0 +1,54 @@ +package tag + +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 WorkspaceTagGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TagContract +} + +// WorkspaceTagGet ... +func (c TagClient) WorkspaceTagGet(ctx context.Context, id WorkspaceTagId) (result WorkspaceTagGetOperationResponse, 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 TagContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/method_workspacetaggetentitystate.go b/resource-manager/apimanagement/2024-05-01/tag/method_workspacetaggetentitystate.go new file mode 100644 index 00000000000..2d112303f1d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/method_workspacetaggetentitystate.go @@ -0,0 +1,46 @@ +package tag + +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 WorkspaceTagGetEntityStateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceTagGetEntityState ... +func (c TagClient) WorkspaceTagGetEntityState(ctx context.Context, id WorkspaceTagId) (result WorkspaceTagGetEntityStateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/method_workspacetaglistbyservice.go b/resource-manager/apimanagement/2024-05-01/tag/method_workspacetaglistbyservice.go new file mode 100644 index 00000000000..e41c7e2b252 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/method_workspacetaglistbyservice.go @@ -0,0 +1,145 @@ +package tag + +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 WorkspaceTagListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TagContract +} + +type WorkspaceTagListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []TagContract +} + +type WorkspaceTagListByServiceOperationOptions struct { + Filter *string + Scope *string + Skip *int64 + Top *int64 +} + +func DefaultWorkspaceTagListByServiceOperationOptions() WorkspaceTagListByServiceOperationOptions { + return WorkspaceTagListByServiceOperationOptions{} +} + +func (o WorkspaceTagListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceTagListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceTagListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Scope != nil { + out.Append("scope", fmt.Sprintf("%v", *o.Scope)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspaceTagListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceTagListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceTagListByService ... +func (c TagClient) WorkspaceTagListByService(ctx context.Context, id WorkspaceId, options WorkspaceTagListByServiceOperationOptions) (result WorkspaceTagListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspaceTagListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/tags", 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 *[]TagContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceTagListByServiceComplete retrieves all the results into a single object +func (c TagClient) WorkspaceTagListByServiceComplete(ctx context.Context, id WorkspaceId, options WorkspaceTagListByServiceOperationOptions) (WorkspaceTagListByServiceCompleteResult, error) { + return c.WorkspaceTagListByServiceCompleteMatchingPredicate(ctx, id, options, TagContractOperationPredicate{}) +} + +// WorkspaceTagListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TagClient) WorkspaceTagListByServiceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options WorkspaceTagListByServiceOperationOptions, predicate TagContractOperationPredicate) (result WorkspaceTagListByServiceCompleteResult, err error) { + items := make([]TagContract, 0) + + resp, err := c.WorkspaceTagListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceTagListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/method_workspacetagupdate.go b/resource-manager/apimanagement/2024-05-01/tag/method_workspacetagupdate.go new file mode 100644 index 00000000000..0d23c5923a8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/method_workspacetagupdate.go @@ -0,0 +1,87 @@ +package tag + +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 WorkspaceTagUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TagContract +} + +type WorkspaceTagUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspaceTagUpdateOperationOptions() WorkspaceTagUpdateOperationOptions { + return WorkspaceTagUpdateOperationOptions{} +} + +func (o WorkspaceTagUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspaceTagUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceTagUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspaceTagUpdate ... +func (c TagClient) WorkspaceTagUpdate(ctx context.Context, id WorkspaceTagId, input TagCreateUpdateParameters, options WorkspaceTagUpdateOperationOptions) (result WorkspaceTagUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 TagContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/model_tagcontract.go b/resource-manager/apimanagement/2024-05-01/tag/model_tagcontract.go new file mode 100644 index 00000000000..9103d40ca71 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/model_tagcontract.go @@ -0,0 +1,11 @@ +package tag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *TagContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/model_tagcontractproperties.go b/resource-manager/apimanagement/2024-05-01/tag/model_tagcontractproperties.go new file mode 100644 index 00000000000..6cd5b7a2218 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/model_tagcontractproperties.go @@ -0,0 +1,8 @@ +package tag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagContractProperties struct { + DisplayName string `json:"displayName"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/model_tagcreateupdateparameters.go b/resource-manager/apimanagement/2024-05-01/tag/model_tagcreateupdateparameters.go new file mode 100644 index 00000000000..0169b289eb8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/model_tagcreateupdateparameters.go @@ -0,0 +1,8 @@ +package tag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagCreateUpdateParameters struct { + Properties *TagContractProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tag/predicates.go b/resource-manager/apimanagement/2024-05-01/tag/predicates.go new file mode 100644 index 00000000000..b05086d88d1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/predicates.go @@ -0,0 +1,27 @@ +package tag + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p TagContractOperationPredicate) Matches(input TagContract) 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/apimanagement/2024-05-01/tag/version.go b/resource-manager/apimanagement/2024-05-01/tag/version.go new file mode 100644 index 00000000000..bdf6683cd32 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tag/version.go @@ -0,0 +1,12 @@ +package tag + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/tag/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/tagapilink/README.md b/resource-manager/apimanagement/2024-05-01/tagapilink/README.md new file mode 100644 index 00000000000..8bff2a7cd67 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagapilink/README.md @@ -0,0 +1,160 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tagapilink` Documentation + +The `tagapilink` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tagapilink" +``` + + +### Client Initialization + +```go +client := tagapilink.NewTagApiLinkClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TagApiLinkClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := tagapilink.NewApiLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue", "apiLinkIdValue") + +payload := tagapilink.TagApiLinkContract{ + // ... +} + + +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: `TagApiLinkClient.Delete` + +```go +ctx := context.TODO() +id := tagapilink.NewApiLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue", "apiLinkIdValue") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagApiLinkClient.Get` + +```go +ctx := context.TODO() +id := tagapilink.NewApiLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue", "apiLinkIdValue") + +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: `TagApiLinkClient.ListByProduct` + +```go +ctx := context.TODO() +id := tagapilink.NewTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue") + +// alternatively `client.ListByProduct(ctx, id, tagapilink.DefaultListByProductOperationOptions())` can be used to do batched pagination +items, err := client.ListByProductComplete(ctx, id, tagapilink.DefaultListByProductOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `TagApiLinkClient.WorkspaceTagApiLinkCreateOrUpdate` + +```go +ctx := context.TODO() +id := tagapilink.NewTagApiLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue", "apiLinkIdValue") + +payload := tagapilink.TagApiLinkContract{ + // ... +} + + +read, err := client.WorkspaceTagApiLinkCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagApiLinkClient.WorkspaceTagApiLinkDelete` + +```go +ctx := context.TODO() +id := tagapilink.NewTagApiLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue", "apiLinkIdValue") + +read, err := client.WorkspaceTagApiLinkDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagApiLinkClient.WorkspaceTagApiLinkGet` + +```go +ctx := context.TODO() +id := tagapilink.NewTagApiLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue", "apiLinkIdValue") + +read, err := client.WorkspaceTagApiLinkGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagApiLinkClient.WorkspaceTagApiLinkListByProduct` + +```go +ctx := context.TODO() +id := tagapilink.NewWorkspaceTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue") + +// alternatively `client.WorkspaceTagApiLinkListByProduct(ctx, id, tagapilink.DefaultWorkspaceTagApiLinkListByProductOperationOptions())` can be used to do batched pagination +items, err := client.WorkspaceTagApiLinkListByProductComplete(ctx, id, tagapilink.DefaultWorkspaceTagApiLinkListByProductOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/tagapilink/client.go b/resource-manager/apimanagement/2024-05-01/tagapilink/client.go new file mode 100644 index 00000000000..a3dcf8d66eb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagapilink/client.go @@ -0,0 +1,26 @@ +package tagapilink + +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 TagApiLinkClient struct { + Client *resourcemanager.Client +} + +func NewTagApiLinkClientWithBaseURI(sdkApi sdkEnv.Api) (*TagApiLinkClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "tagapilink", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TagApiLinkClient: %+v", err) + } + + return &TagApiLinkClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/tagapilink/id_apilink.go b/resource-manager/apimanagement/2024-05-01/tagapilink/id_apilink.go new file mode 100644 index 00000000000..8f12afdcae2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagapilink/id_apilink.go @@ -0,0 +1,148 @@ +package tagapilink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ApiLinkId{}) +} + +var _ resourceids.ResourceId = &ApiLinkId{} + +// ApiLinkId is a struct representing the Resource ID for a Api Link +type ApiLinkId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + TagId string + ApiLinkId string +} + +// NewApiLinkID returns a new ApiLinkId struct +func NewApiLinkID(subscriptionId string, resourceGroupName string, serviceName string, tagId string, apiLinkId string) ApiLinkId { + return ApiLinkId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + TagId: tagId, + ApiLinkId: apiLinkId, + } +} + +// ParseApiLinkID parses 'input' into a ApiLinkId +func ParseApiLinkID(input string) (*ApiLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiLinkId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseApiLinkIDInsensitively parses 'input' case-insensitively into a ApiLinkId +// note: this method should only be used for API response data and not user input +func ParseApiLinkIDInsensitively(input string) (*ApiLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&ApiLinkId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ApiLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ApiLinkId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.TagId, ok = input.Parsed["tagId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagId", input) + } + + if id.ApiLinkId, ok = input.Parsed["apiLinkId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiLinkId", input) + } + + return nil +} + +// ValidateApiLinkID checks that 'input' can be parsed as a Api Link ID +func ValidateApiLinkID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseApiLinkID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Api Link ID +func (id ApiLinkId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/tags/%s/apiLinks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.TagId, id.ApiLinkId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Api Link ID +func (id ApiLinkId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticTags", "tags", "tags"), + resourceids.UserSpecifiedSegment("tagId", "tagIdValue"), + resourceids.StaticSegment("staticApiLinks", "apiLinks", "apiLinks"), + resourceids.UserSpecifiedSegment("apiLinkId", "apiLinkIdValue"), + } +} + +// String returns a human-readable description of this Api Link ID +func (id ApiLinkId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Tag: %q", id.TagId), + fmt.Sprintf("Api Link: %q", id.ApiLinkId), + } + return fmt.Sprintf("Api Link (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/tagapilink/id_apilink_test.go b/resource-manager/apimanagement/2024-05-01/tagapilink/id_apilink_test.go new file mode 100644 index 00000000000..dc4e5bf608b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagapilink/id_apilink_test.go @@ -0,0 +1,372 @@ +package tagapilink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ApiLinkId{} + +func TestNewApiLinkID(t *testing.T) { + id := NewApiLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue", "apiLinkIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.TagId != "tagIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'TagId'", id.TagId, "tagIdValue") + } + + if id.ApiLinkId != "apiLinkIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiLinkId'", id.ApiLinkId, "apiLinkIdValue") + } +} + +func TestFormatApiLinkID(t *testing.T) { + actual := NewApiLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue", "apiLinkIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/apiLinks/apiLinkIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseApiLinkID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/apiLinks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/apiLinks/apiLinkIdValue", + Expected: &ApiLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + TagId: "tagIdValue", + ApiLinkId: "apiLinkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/apiLinks/apiLinkIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiLinkID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + if actual.ApiLinkId != v.Expected.ApiLinkId { + t.Fatalf("Expected %q but got %q for ApiLinkId", v.Expected.ApiLinkId, actual.ApiLinkId) + } + + } +} + +func TestParseApiLinkIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ApiLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS/tAgIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/apiLinks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS/tAgIdVaLuE/aPiLiNkS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/apiLinks/apiLinkIdValue", + Expected: &ApiLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + TagId: "tagIdValue", + ApiLinkId: "apiLinkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/apiLinks/apiLinkIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS/tAgIdVaLuE/aPiLiNkS/aPiLiNkIdVaLuE", + Expected: &ApiLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + TagId: "tAgIdVaLuE", + ApiLinkId: "aPiLiNkIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS/tAgIdVaLuE/aPiLiNkS/aPiLiNkIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseApiLinkIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + if actual.ApiLinkId != v.Expected.ApiLinkId { + t.Fatalf("Expected %q but got %q for ApiLinkId", v.Expected.ApiLinkId, actual.ApiLinkId) + } + + } +} + +func TestSegmentsForApiLinkId(t *testing.T) { + segments := ApiLinkId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ApiLinkId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/tagapilink/id_tag.go b/resource-manager/apimanagement/2024-05-01/tagapilink/id_tag.go new file mode 100644 index 00000000000..d8e00e21e9f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagapilink/id_tag.go @@ -0,0 +1,139 @@ +package tagapilink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TagId{}) +} + +var _ resourceids.ResourceId = &TagId{} + +// TagId is a struct representing the Resource ID for a Tag +type TagId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + TagId string +} + +// NewTagID returns a new TagId struct +func NewTagID(subscriptionId string, resourceGroupName string, serviceName string, tagId string) TagId { + return TagId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + TagId: tagId, + } +} + +// ParseTagID parses 'input' into a TagId +func ParseTagID(input string) (*TagId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTagIDInsensitively parses 'input' case-insensitively into a TagId +// note: this method should only be used for API response data and not user input +func ParseTagIDInsensitively(input string) (*TagId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TagId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.TagId, ok = input.Parsed["tagId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagId", input) + } + + return nil +} + +// ValidateTagID checks that 'input' can be parsed as a Tag ID +func ValidateTagID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseTagID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Tag ID +func (id TagId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/tags/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.TagId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Tag ID +func (id TagId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticTags", "tags", "tags"), + resourceids.UserSpecifiedSegment("tagId", "tagIdValue"), + } +} + +// String returns a human-readable description of this Tag ID +func (id TagId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Tag: %q", id.TagId), + } + return fmt.Sprintf("Tag (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/tagapilink/id_tag_test.go b/resource-manager/apimanagement/2024-05-01/tagapilink/id_tag_test.go new file mode 100644 index 00000000000..c3eecaa1c08 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagapilink/id_tag_test.go @@ -0,0 +1,327 @@ +package tagapilink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TagId{} + +func TestNewTagID(t *testing.T) { + id := NewTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.TagId != "tagIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'TagId'", id.TagId, "tagIdValue") + } +} + +func TestFormatTagID(t *testing.T) { + actual := NewTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTagID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue", + Expected: &TagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + TagId: "tagIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + } +} + +func TestParseTagIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue", + Expected: &TagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + TagId: "tagIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS/tAgIdVaLuE", + Expected: &TagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + TagId: "tAgIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS/tAgIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + } +} + +func TestSegmentsForTagId(t *testing.T) { + segments := TagId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TagId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/tagapilink/id_tagapilink.go b/resource-manager/apimanagement/2024-05-01/tagapilink/id_tagapilink.go new file mode 100644 index 00000000000..59e43c8dd36 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagapilink/id_tagapilink.go @@ -0,0 +1,157 @@ +package tagapilink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TagApiLinkId{}) +} + +var _ resourceids.ResourceId = &TagApiLinkId{} + +// TagApiLinkId is a struct representing the Resource ID for a Tag Api Link +type TagApiLinkId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + TagId string + ApiLinkId string +} + +// NewTagApiLinkID returns a new TagApiLinkId struct +func NewTagApiLinkID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, tagId string, apiLinkId string) TagApiLinkId { + return TagApiLinkId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + TagId: tagId, + ApiLinkId: apiLinkId, + } +} + +// ParseTagApiLinkID parses 'input' into a TagApiLinkId +func ParseTagApiLinkID(input string) (*TagApiLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagApiLinkId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagApiLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTagApiLinkIDInsensitively parses 'input' case-insensitively into a TagApiLinkId +// note: this method should only be used for API response data and not user input +func ParseTagApiLinkIDInsensitively(input string) (*TagApiLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagApiLinkId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagApiLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TagApiLinkId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.TagId, ok = input.Parsed["tagId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagId", input) + } + + if id.ApiLinkId, ok = input.Parsed["apiLinkId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "apiLinkId", input) + } + + return nil +} + +// ValidateTagApiLinkID checks that 'input' can be parsed as a Tag Api Link ID +func ValidateTagApiLinkID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseTagApiLinkID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Tag Api Link ID +func (id TagApiLinkId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/tags/%s/apiLinks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.TagId, id.ApiLinkId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Tag Api Link ID +func (id TagApiLinkId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticTags", "tags", "tags"), + resourceids.UserSpecifiedSegment("tagId", "tagIdValue"), + resourceids.StaticSegment("staticApiLinks", "apiLinks", "apiLinks"), + resourceids.UserSpecifiedSegment("apiLinkId", "apiLinkIdValue"), + } +} + +// String returns a human-readable description of this Tag Api Link ID +func (id TagApiLinkId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Tag: %q", id.TagId), + fmt.Sprintf("Api Link: %q", id.ApiLinkId), + } + return fmt.Sprintf("Tag Api Link (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/tagapilink/id_tagapilink_test.go b/resource-manager/apimanagement/2024-05-01/tagapilink/id_tagapilink_test.go new file mode 100644 index 00000000000..1140096e325 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagapilink/id_tagapilink_test.go @@ -0,0 +1,417 @@ +package tagapilink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TagApiLinkId{} + +func TestNewTagApiLinkID(t *testing.T) { + id := NewTagApiLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue", "apiLinkIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.TagId != "tagIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'TagId'", id.TagId, "tagIdValue") + } + + if id.ApiLinkId != "apiLinkIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ApiLinkId'", id.ApiLinkId, "apiLinkIdValue") + } +} + +func TestFormatTagApiLinkID(t *testing.T) { + actual := NewTagApiLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue", "apiLinkIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/apiLinks/apiLinkIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTagApiLinkID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagApiLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/apiLinks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/apiLinks/apiLinkIdValue", + Expected: &TagApiLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + TagId: "tagIdValue", + ApiLinkId: "apiLinkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/apiLinks/apiLinkIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagApiLinkID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + if actual.ApiLinkId != v.Expected.ApiLinkId { + t.Fatalf("Expected %q but got %q for ApiLinkId", v.Expected.ApiLinkId, actual.ApiLinkId) + } + + } +} + +func TestParseTagApiLinkIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagApiLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS/tAgIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/apiLinks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS/tAgIdVaLuE/aPiLiNkS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/apiLinks/apiLinkIdValue", + Expected: &TagApiLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + TagId: "tagIdValue", + ApiLinkId: "apiLinkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/apiLinks/apiLinkIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS/tAgIdVaLuE/aPiLiNkS/aPiLiNkIdVaLuE", + Expected: &TagApiLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + TagId: "tAgIdVaLuE", + ApiLinkId: "aPiLiNkIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS/tAgIdVaLuE/aPiLiNkS/aPiLiNkIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagApiLinkIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + if actual.ApiLinkId != v.Expected.ApiLinkId { + t.Fatalf("Expected %q but got %q for ApiLinkId", v.Expected.ApiLinkId, actual.ApiLinkId) + } + + } +} + +func TestSegmentsForTagApiLinkId(t *testing.T) { + segments := TagApiLinkId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TagApiLinkId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/tagapilink/id_workspacetag.go b/resource-manager/apimanagement/2024-05-01/tagapilink/id_workspacetag.go new file mode 100644 index 00000000000..a7ea89f58c3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagapilink/id_workspacetag.go @@ -0,0 +1,148 @@ +package tagapilink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceTagId{}) +} + +var _ resourceids.ResourceId = &WorkspaceTagId{} + +// WorkspaceTagId is a struct representing the Resource ID for a Workspace Tag +type WorkspaceTagId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + TagId string +} + +// NewWorkspaceTagID returns a new WorkspaceTagId struct +func NewWorkspaceTagID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, tagId string) WorkspaceTagId { + return WorkspaceTagId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + TagId: tagId, + } +} + +// ParseWorkspaceTagID parses 'input' into a WorkspaceTagId +func ParseWorkspaceTagID(input string) (*WorkspaceTagId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceTagId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceTagId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceTagIDInsensitively parses 'input' case-insensitively into a WorkspaceTagId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceTagIDInsensitively(input string) (*WorkspaceTagId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceTagId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceTagId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceTagId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.TagId, ok = input.Parsed["tagId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagId", input) + } + + return nil +} + +// ValidateWorkspaceTagID checks that 'input' can be parsed as a Workspace Tag ID +func ValidateWorkspaceTagID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceTagID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Tag ID +func (id WorkspaceTagId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/tags/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.TagId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Tag ID +func (id WorkspaceTagId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticTags", "tags", "tags"), + resourceids.UserSpecifiedSegment("tagId", "tagIdValue"), + } +} + +// String returns a human-readable description of this Workspace Tag ID +func (id WorkspaceTagId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Tag: %q", id.TagId), + } + return fmt.Sprintf("Workspace Tag (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/tagapilink/id_workspacetag_test.go b/resource-manager/apimanagement/2024-05-01/tagapilink/id_workspacetag_test.go new file mode 100644 index 00000000000..fab1c585a40 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagapilink/id_workspacetag_test.go @@ -0,0 +1,372 @@ +package tagapilink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceTagId{} + +func TestNewWorkspaceTagID(t *testing.T) { + id := NewWorkspaceTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.TagId != "tagIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'TagId'", id.TagId, "tagIdValue") + } +} + +func TestFormatWorkspaceTagID(t *testing.T) { + actual := NewWorkspaceTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceTagID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceTagId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue", + Expected: &WorkspaceTagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + TagId: "tagIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceTagID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + } +} + +func TestParseWorkspaceTagIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceTagId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue", + Expected: &WorkspaceTagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + TagId: "tagIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS/tAgIdVaLuE", + Expected: &WorkspaceTagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + TagId: "tAgIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS/tAgIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceTagIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + } +} + +func TestSegmentsForWorkspaceTagId(t *testing.T) { + segments := WorkspaceTagId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceTagId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/tagapilink/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/tagapilink/method_createorupdate.go new file mode 100644 index 00000000000..0b09901bfc5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagapilink/method_createorupdate.go @@ -0,0 +1,59 @@ +package tagapilink + +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 *TagApiLinkContract +} + +// CreateOrUpdate ... +func (c TagApiLinkClient) CreateOrUpdate(ctx context.Context, id ApiLinkId, input TagApiLinkContract) (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 TagApiLinkContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagapilink/method_delete.go b/resource-manager/apimanagement/2024-05-01/tagapilink/method_delete.go new file mode 100644 index 00000000000..4831bd992c9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagapilink/method_delete.go @@ -0,0 +1,47 @@ +package tagapilink + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c TagApiLinkClient) Delete(ctx context.Context, id ApiLinkId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagapilink/method_get.go b/resource-manager/apimanagement/2024-05-01/tagapilink/method_get.go new file mode 100644 index 00000000000..8de9c2a323d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagapilink/method_get.go @@ -0,0 +1,54 @@ +package tagapilink + +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 *TagApiLinkContract +} + +// Get ... +func (c TagApiLinkClient) Get(ctx context.Context, id ApiLinkId) (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 TagApiLinkContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagapilink/method_listbyproduct.go b/resource-manager/apimanagement/2024-05-01/tagapilink/method_listbyproduct.go new file mode 100644 index 00000000000..4c0cda2c870 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagapilink/method_listbyproduct.go @@ -0,0 +1,141 @@ +package tagapilink + +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 ListByProductOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TagApiLinkContract +} + +type ListByProductCompleteResult struct { + LatestHttpResponse *http.Response + Items []TagApiLinkContract +} + +type ListByProductOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByProductOperationOptions() ListByProductOperationOptions { + return ListByProductOperationOptions{} +} + +func (o ListByProductOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByProductOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByProductOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByProductCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByProductCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByProduct ... +func (c TagApiLinkClient) ListByProduct(ctx context.Context, id TagId, options ListByProductOperationOptions) (result ListByProductOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByProductCustomPager{}, + Path: fmt.Sprintf("%s/apiLinks", 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 *[]TagApiLinkContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByProductComplete retrieves all the results into a single object +func (c TagApiLinkClient) ListByProductComplete(ctx context.Context, id TagId, options ListByProductOperationOptions) (ListByProductCompleteResult, error) { + return c.ListByProductCompleteMatchingPredicate(ctx, id, options, TagApiLinkContractOperationPredicate{}) +} + +// ListByProductCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TagApiLinkClient) ListByProductCompleteMatchingPredicate(ctx context.Context, id TagId, options ListByProductOperationOptions, predicate TagApiLinkContractOperationPredicate) (result ListByProductCompleteResult, err error) { + items := make([]TagApiLinkContract, 0) + + resp, err := c.ListByProduct(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByProductCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagapilink/method_workspacetagapilinkcreateorupdate.go b/resource-manager/apimanagement/2024-05-01/tagapilink/method_workspacetagapilinkcreateorupdate.go new file mode 100644 index 00000000000..b8a0dc48684 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagapilink/method_workspacetagapilinkcreateorupdate.go @@ -0,0 +1,59 @@ +package tagapilink + +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 WorkspaceTagApiLinkCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TagApiLinkContract +} + +// WorkspaceTagApiLinkCreateOrUpdate ... +func (c TagApiLinkClient) WorkspaceTagApiLinkCreateOrUpdate(ctx context.Context, id TagApiLinkId, input TagApiLinkContract) (result WorkspaceTagApiLinkCreateOrUpdateOperationResponse, 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 TagApiLinkContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagapilink/method_workspacetagapilinkdelete.go b/resource-manager/apimanagement/2024-05-01/tagapilink/method_workspacetagapilinkdelete.go new file mode 100644 index 00000000000..ee825dbccc7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagapilink/method_workspacetagapilinkdelete.go @@ -0,0 +1,47 @@ +package tagapilink + +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 WorkspaceTagApiLinkDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceTagApiLinkDelete ... +func (c TagApiLinkClient) WorkspaceTagApiLinkDelete(ctx context.Context, id TagApiLinkId) (result WorkspaceTagApiLinkDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagapilink/method_workspacetagapilinkget.go b/resource-manager/apimanagement/2024-05-01/tagapilink/method_workspacetagapilinkget.go new file mode 100644 index 00000000000..3eddb1e9cc1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagapilink/method_workspacetagapilinkget.go @@ -0,0 +1,54 @@ +package tagapilink + +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 WorkspaceTagApiLinkGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TagApiLinkContract +} + +// WorkspaceTagApiLinkGet ... +func (c TagApiLinkClient) WorkspaceTagApiLinkGet(ctx context.Context, id TagApiLinkId) (result WorkspaceTagApiLinkGetOperationResponse, 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 TagApiLinkContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagapilink/method_workspacetagapilinklistbyproduct.go b/resource-manager/apimanagement/2024-05-01/tagapilink/method_workspacetagapilinklistbyproduct.go new file mode 100644 index 00000000000..b39a8283dfe --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagapilink/method_workspacetagapilinklistbyproduct.go @@ -0,0 +1,141 @@ +package tagapilink + +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 WorkspaceTagApiLinkListByProductOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TagApiLinkContract +} + +type WorkspaceTagApiLinkListByProductCompleteResult struct { + LatestHttpResponse *http.Response + Items []TagApiLinkContract +} + +type WorkspaceTagApiLinkListByProductOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultWorkspaceTagApiLinkListByProductOperationOptions() WorkspaceTagApiLinkListByProductOperationOptions { + return WorkspaceTagApiLinkListByProductOperationOptions{} +} + +func (o WorkspaceTagApiLinkListByProductOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceTagApiLinkListByProductOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceTagApiLinkListByProductOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspaceTagApiLinkListByProductCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceTagApiLinkListByProductCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceTagApiLinkListByProduct ... +func (c TagApiLinkClient) WorkspaceTagApiLinkListByProduct(ctx context.Context, id WorkspaceTagId, options WorkspaceTagApiLinkListByProductOperationOptions) (result WorkspaceTagApiLinkListByProductOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspaceTagApiLinkListByProductCustomPager{}, + Path: fmt.Sprintf("%s/apiLinks", 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 *[]TagApiLinkContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceTagApiLinkListByProductComplete retrieves all the results into a single object +func (c TagApiLinkClient) WorkspaceTagApiLinkListByProductComplete(ctx context.Context, id WorkspaceTagId, options WorkspaceTagApiLinkListByProductOperationOptions) (WorkspaceTagApiLinkListByProductCompleteResult, error) { + return c.WorkspaceTagApiLinkListByProductCompleteMatchingPredicate(ctx, id, options, TagApiLinkContractOperationPredicate{}) +} + +// WorkspaceTagApiLinkListByProductCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TagApiLinkClient) WorkspaceTagApiLinkListByProductCompleteMatchingPredicate(ctx context.Context, id WorkspaceTagId, options WorkspaceTagApiLinkListByProductOperationOptions, predicate TagApiLinkContractOperationPredicate) (result WorkspaceTagApiLinkListByProductCompleteResult, err error) { + items := make([]TagApiLinkContract, 0) + + resp, err := c.WorkspaceTagApiLinkListByProduct(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceTagApiLinkListByProductCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagapilink/model_tagapilinkcontract.go b/resource-manager/apimanagement/2024-05-01/tagapilink/model_tagapilinkcontract.go new file mode 100644 index 00000000000..a36b79eeaf8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagapilink/model_tagapilinkcontract.go @@ -0,0 +1,11 @@ +package tagapilink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagApiLinkContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *TagApiLinkContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tagapilink/model_tagapilinkcontractproperties.go b/resource-manager/apimanagement/2024-05-01/tagapilink/model_tagapilinkcontractproperties.go new file mode 100644 index 00000000000..f39b4a50f0c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagapilink/model_tagapilinkcontractproperties.go @@ -0,0 +1,8 @@ +package tagapilink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagApiLinkContractProperties struct { + ApiId string `json:"apiId"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tagapilink/predicates.go b/resource-manager/apimanagement/2024-05-01/tagapilink/predicates.go new file mode 100644 index 00000000000..3473dbce624 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagapilink/predicates.go @@ -0,0 +1,27 @@ +package tagapilink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagApiLinkContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p TagApiLinkContractOperationPredicate) Matches(input TagApiLinkContract) 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/apimanagement/2024-05-01/tagapilink/version.go b/resource-manager/apimanagement/2024-05-01/tagapilink/version.go new file mode 100644 index 00000000000..0420fe9781f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagapilink/version.go @@ -0,0 +1,12 @@ +package tagapilink + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/tagapilink/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/tagoperationlink/README.md b/resource-manager/apimanagement/2024-05-01/tagoperationlink/README.md new file mode 100644 index 00000000000..bda73511b90 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagoperationlink/README.md @@ -0,0 +1,160 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tagoperationlink` Documentation + +The `tagoperationlink` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tagoperationlink" +``` + + +### Client Initialization + +```go +client := tagoperationlink.NewTagOperationLinkClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TagOperationLinkClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := tagoperationlink.NewOperationLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue", "operationLinkIdValue") + +payload := tagoperationlink.TagOperationLinkContract{ + // ... +} + + +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: `TagOperationLinkClient.Delete` + +```go +ctx := context.TODO() +id := tagoperationlink.NewOperationLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue", "operationLinkIdValue") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagOperationLinkClient.Get` + +```go +ctx := context.TODO() +id := tagoperationlink.NewOperationLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue", "operationLinkIdValue") + +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: `TagOperationLinkClient.ListByProduct` + +```go +ctx := context.TODO() +id := tagoperationlink.NewTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue") + +// alternatively `client.ListByProduct(ctx, id, tagoperationlink.DefaultListByProductOperationOptions())` can be used to do batched pagination +items, err := client.ListByProductComplete(ctx, id, tagoperationlink.DefaultListByProductOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `TagOperationLinkClient.WorkspaceTagOperationLinkCreateOrUpdate` + +```go +ctx := context.TODO() +id := tagoperationlink.NewTagOperationLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue", "operationLinkIdValue") + +payload := tagoperationlink.TagOperationLinkContract{ + // ... +} + + +read, err := client.WorkspaceTagOperationLinkCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagOperationLinkClient.WorkspaceTagOperationLinkDelete` + +```go +ctx := context.TODO() +id := tagoperationlink.NewTagOperationLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue", "operationLinkIdValue") + +read, err := client.WorkspaceTagOperationLinkDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagOperationLinkClient.WorkspaceTagOperationLinkGet` + +```go +ctx := context.TODO() +id := tagoperationlink.NewTagOperationLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue", "operationLinkIdValue") + +read, err := client.WorkspaceTagOperationLinkGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagOperationLinkClient.WorkspaceTagOperationLinkListByProduct` + +```go +ctx := context.TODO() +id := tagoperationlink.NewWorkspaceTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue") + +// alternatively `client.WorkspaceTagOperationLinkListByProduct(ctx, id, tagoperationlink.DefaultWorkspaceTagOperationLinkListByProductOperationOptions())` can be used to do batched pagination +items, err := client.WorkspaceTagOperationLinkListByProductComplete(ctx, id, tagoperationlink.DefaultWorkspaceTagOperationLinkListByProductOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/tagoperationlink/client.go b/resource-manager/apimanagement/2024-05-01/tagoperationlink/client.go new file mode 100644 index 00000000000..e582ef4198c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagoperationlink/client.go @@ -0,0 +1,26 @@ +package tagoperationlink + +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 TagOperationLinkClient struct { + Client *resourcemanager.Client +} + +func NewTagOperationLinkClientWithBaseURI(sdkApi sdkEnv.Api) (*TagOperationLinkClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "tagoperationlink", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TagOperationLinkClient: %+v", err) + } + + return &TagOperationLinkClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/tagoperationlink/id_operationlink.go b/resource-manager/apimanagement/2024-05-01/tagoperationlink/id_operationlink.go new file mode 100644 index 00000000000..c714bd0244c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagoperationlink/id_operationlink.go @@ -0,0 +1,148 @@ +package tagoperationlink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&OperationLinkId{}) +} + +var _ resourceids.ResourceId = &OperationLinkId{} + +// OperationLinkId is a struct representing the Resource ID for a Operation Link +type OperationLinkId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + TagId string + OperationLinkId string +} + +// NewOperationLinkID returns a new OperationLinkId struct +func NewOperationLinkID(subscriptionId string, resourceGroupName string, serviceName string, tagId string, operationLinkId string) OperationLinkId { + return OperationLinkId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + TagId: tagId, + OperationLinkId: operationLinkId, + } +} + +// ParseOperationLinkID parses 'input' into a OperationLinkId +func ParseOperationLinkID(input string) (*OperationLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&OperationLinkId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OperationLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseOperationLinkIDInsensitively parses 'input' case-insensitively into a OperationLinkId +// note: this method should only be used for API response data and not user input +func ParseOperationLinkIDInsensitively(input string) (*OperationLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&OperationLinkId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OperationLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *OperationLinkId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.TagId, ok = input.Parsed["tagId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagId", input) + } + + if id.OperationLinkId, ok = input.Parsed["operationLinkId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "operationLinkId", input) + } + + return nil +} + +// ValidateOperationLinkID checks that 'input' can be parsed as a Operation Link ID +func ValidateOperationLinkID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseOperationLinkID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Operation Link ID +func (id OperationLinkId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/tags/%s/operationLinks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.TagId, id.OperationLinkId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Operation Link ID +func (id OperationLinkId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticTags", "tags", "tags"), + resourceids.UserSpecifiedSegment("tagId", "tagIdValue"), + resourceids.StaticSegment("staticOperationLinks", "operationLinks", "operationLinks"), + resourceids.UserSpecifiedSegment("operationLinkId", "operationLinkIdValue"), + } +} + +// String returns a human-readable description of this Operation Link ID +func (id OperationLinkId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Tag: %q", id.TagId), + fmt.Sprintf("Operation Link: %q", id.OperationLinkId), + } + return fmt.Sprintf("Operation Link (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/tagoperationlink/id_operationlink_test.go b/resource-manager/apimanagement/2024-05-01/tagoperationlink/id_operationlink_test.go new file mode 100644 index 00000000000..0e7f82ddbc3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagoperationlink/id_operationlink_test.go @@ -0,0 +1,372 @@ +package tagoperationlink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &OperationLinkId{} + +func TestNewOperationLinkID(t *testing.T) { + id := NewOperationLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue", "operationLinkIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.TagId != "tagIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'TagId'", id.TagId, "tagIdValue") + } + + if id.OperationLinkId != "operationLinkIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'OperationLinkId'", id.OperationLinkId, "operationLinkIdValue") + } +} + +func TestFormatOperationLinkID(t *testing.T) { + actual := NewOperationLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue", "operationLinkIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/operationLinks/operationLinkIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseOperationLinkID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OperationLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/operationLinks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/operationLinks/operationLinkIdValue", + Expected: &OperationLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + TagId: "tagIdValue", + OperationLinkId: "operationLinkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/operationLinks/operationLinkIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOperationLinkID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + if actual.OperationLinkId != v.Expected.OperationLinkId { + t.Fatalf("Expected %q but got %q for OperationLinkId", v.Expected.OperationLinkId, actual.OperationLinkId) + } + + } +} + +func TestParseOperationLinkIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OperationLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS/tAgIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/operationLinks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS/tAgIdVaLuE/oPeRaTiOnLiNkS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/operationLinks/operationLinkIdValue", + Expected: &OperationLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + TagId: "tagIdValue", + OperationLinkId: "operationLinkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/operationLinks/operationLinkIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS/tAgIdVaLuE/oPeRaTiOnLiNkS/oPeRaTiOnLiNkIdVaLuE", + Expected: &OperationLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + TagId: "tAgIdVaLuE", + OperationLinkId: "oPeRaTiOnLiNkIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS/tAgIdVaLuE/oPeRaTiOnLiNkS/oPeRaTiOnLiNkIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOperationLinkIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + if actual.OperationLinkId != v.Expected.OperationLinkId { + t.Fatalf("Expected %q but got %q for OperationLinkId", v.Expected.OperationLinkId, actual.OperationLinkId) + } + + } +} + +func TestSegmentsForOperationLinkId(t *testing.T) { + segments := OperationLinkId{}.Segments() + if len(segments) == 0 { + t.Fatalf("OperationLinkId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/tagoperationlink/id_tag.go b/resource-manager/apimanagement/2024-05-01/tagoperationlink/id_tag.go new file mode 100644 index 00000000000..c2c5d5834d5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagoperationlink/id_tag.go @@ -0,0 +1,139 @@ +package tagoperationlink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TagId{}) +} + +var _ resourceids.ResourceId = &TagId{} + +// TagId is a struct representing the Resource ID for a Tag +type TagId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + TagId string +} + +// NewTagID returns a new TagId struct +func NewTagID(subscriptionId string, resourceGroupName string, serviceName string, tagId string) TagId { + return TagId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + TagId: tagId, + } +} + +// ParseTagID parses 'input' into a TagId +func ParseTagID(input string) (*TagId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTagIDInsensitively parses 'input' case-insensitively into a TagId +// note: this method should only be used for API response data and not user input +func ParseTagIDInsensitively(input string) (*TagId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TagId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.TagId, ok = input.Parsed["tagId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagId", input) + } + + return nil +} + +// ValidateTagID checks that 'input' can be parsed as a Tag ID +func ValidateTagID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseTagID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Tag ID +func (id TagId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/tags/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.TagId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Tag ID +func (id TagId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticTags", "tags", "tags"), + resourceids.UserSpecifiedSegment("tagId", "tagIdValue"), + } +} + +// String returns a human-readable description of this Tag ID +func (id TagId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Tag: %q", id.TagId), + } + return fmt.Sprintf("Tag (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/tagoperationlink/id_tag_test.go b/resource-manager/apimanagement/2024-05-01/tagoperationlink/id_tag_test.go new file mode 100644 index 00000000000..5b330f265e3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagoperationlink/id_tag_test.go @@ -0,0 +1,327 @@ +package tagoperationlink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TagId{} + +func TestNewTagID(t *testing.T) { + id := NewTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.TagId != "tagIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'TagId'", id.TagId, "tagIdValue") + } +} + +func TestFormatTagID(t *testing.T) { + actual := NewTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTagID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue", + Expected: &TagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + TagId: "tagIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + } +} + +func TestParseTagIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue", + Expected: &TagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + TagId: "tagIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS/tAgIdVaLuE", + Expected: &TagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + TagId: "tAgIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS/tAgIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + } +} + +func TestSegmentsForTagId(t *testing.T) { + segments := TagId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TagId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/tagoperationlink/id_tagoperationlink.go b/resource-manager/apimanagement/2024-05-01/tagoperationlink/id_tagoperationlink.go new file mode 100644 index 00000000000..8d1d98640ce --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagoperationlink/id_tagoperationlink.go @@ -0,0 +1,157 @@ +package tagoperationlink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TagOperationLinkId{}) +} + +var _ resourceids.ResourceId = &TagOperationLinkId{} + +// TagOperationLinkId is a struct representing the Resource ID for a Tag Operation Link +type TagOperationLinkId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + TagId string + OperationLinkId string +} + +// NewTagOperationLinkID returns a new TagOperationLinkId struct +func NewTagOperationLinkID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, tagId string, operationLinkId string) TagOperationLinkId { + return TagOperationLinkId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + TagId: tagId, + OperationLinkId: operationLinkId, + } +} + +// ParseTagOperationLinkID parses 'input' into a TagOperationLinkId +func ParseTagOperationLinkID(input string) (*TagOperationLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagOperationLinkId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagOperationLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTagOperationLinkIDInsensitively parses 'input' case-insensitively into a TagOperationLinkId +// note: this method should only be used for API response data and not user input +func ParseTagOperationLinkIDInsensitively(input string) (*TagOperationLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagOperationLinkId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagOperationLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TagOperationLinkId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.TagId, ok = input.Parsed["tagId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagId", input) + } + + if id.OperationLinkId, ok = input.Parsed["operationLinkId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "operationLinkId", input) + } + + return nil +} + +// ValidateTagOperationLinkID checks that 'input' can be parsed as a Tag Operation Link ID +func ValidateTagOperationLinkID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseTagOperationLinkID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Tag Operation Link ID +func (id TagOperationLinkId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/tags/%s/operationLinks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.TagId, id.OperationLinkId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Tag Operation Link ID +func (id TagOperationLinkId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticTags", "tags", "tags"), + resourceids.UserSpecifiedSegment("tagId", "tagIdValue"), + resourceids.StaticSegment("staticOperationLinks", "operationLinks", "operationLinks"), + resourceids.UserSpecifiedSegment("operationLinkId", "operationLinkIdValue"), + } +} + +// String returns a human-readable description of this Tag Operation Link ID +func (id TagOperationLinkId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Tag: %q", id.TagId), + fmt.Sprintf("Operation Link: %q", id.OperationLinkId), + } + return fmt.Sprintf("Tag Operation Link (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/tagoperationlink/id_tagoperationlink_test.go b/resource-manager/apimanagement/2024-05-01/tagoperationlink/id_tagoperationlink_test.go new file mode 100644 index 00000000000..da7d7c8a694 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagoperationlink/id_tagoperationlink_test.go @@ -0,0 +1,417 @@ +package tagoperationlink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TagOperationLinkId{} + +func TestNewTagOperationLinkID(t *testing.T) { + id := NewTagOperationLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue", "operationLinkIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.TagId != "tagIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'TagId'", id.TagId, "tagIdValue") + } + + if id.OperationLinkId != "operationLinkIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'OperationLinkId'", id.OperationLinkId, "operationLinkIdValue") + } +} + +func TestFormatTagOperationLinkID(t *testing.T) { + actual := NewTagOperationLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue", "operationLinkIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/operationLinks/operationLinkIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTagOperationLinkID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagOperationLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/operationLinks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/operationLinks/operationLinkIdValue", + Expected: &TagOperationLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + TagId: "tagIdValue", + OperationLinkId: "operationLinkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/operationLinks/operationLinkIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagOperationLinkID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + if actual.OperationLinkId != v.Expected.OperationLinkId { + t.Fatalf("Expected %q but got %q for OperationLinkId", v.Expected.OperationLinkId, actual.OperationLinkId) + } + + } +} + +func TestParseTagOperationLinkIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagOperationLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS/tAgIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/operationLinks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS/tAgIdVaLuE/oPeRaTiOnLiNkS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/operationLinks/operationLinkIdValue", + Expected: &TagOperationLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + TagId: "tagIdValue", + OperationLinkId: "operationLinkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/operationLinks/operationLinkIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS/tAgIdVaLuE/oPeRaTiOnLiNkS/oPeRaTiOnLiNkIdVaLuE", + Expected: &TagOperationLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + TagId: "tAgIdVaLuE", + OperationLinkId: "oPeRaTiOnLiNkIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS/tAgIdVaLuE/oPeRaTiOnLiNkS/oPeRaTiOnLiNkIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagOperationLinkIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + if actual.OperationLinkId != v.Expected.OperationLinkId { + t.Fatalf("Expected %q but got %q for OperationLinkId", v.Expected.OperationLinkId, actual.OperationLinkId) + } + + } +} + +func TestSegmentsForTagOperationLinkId(t *testing.T) { + segments := TagOperationLinkId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TagOperationLinkId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/tagoperationlink/id_workspacetag.go b/resource-manager/apimanagement/2024-05-01/tagoperationlink/id_workspacetag.go new file mode 100644 index 00000000000..9b722df3460 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagoperationlink/id_workspacetag.go @@ -0,0 +1,148 @@ +package tagoperationlink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceTagId{}) +} + +var _ resourceids.ResourceId = &WorkspaceTagId{} + +// WorkspaceTagId is a struct representing the Resource ID for a Workspace Tag +type WorkspaceTagId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + TagId string +} + +// NewWorkspaceTagID returns a new WorkspaceTagId struct +func NewWorkspaceTagID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, tagId string) WorkspaceTagId { + return WorkspaceTagId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + TagId: tagId, + } +} + +// ParseWorkspaceTagID parses 'input' into a WorkspaceTagId +func ParseWorkspaceTagID(input string) (*WorkspaceTagId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceTagId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceTagId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceTagIDInsensitively parses 'input' case-insensitively into a WorkspaceTagId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceTagIDInsensitively(input string) (*WorkspaceTagId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceTagId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceTagId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceTagId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.TagId, ok = input.Parsed["tagId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagId", input) + } + + return nil +} + +// ValidateWorkspaceTagID checks that 'input' can be parsed as a Workspace Tag ID +func ValidateWorkspaceTagID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceTagID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Tag ID +func (id WorkspaceTagId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/tags/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.TagId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Tag ID +func (id WorkspaceTagId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticTags", "tags", "tags"), + resourceids.UserSpecifiedSegment("tagId", "tagIdValue"), + } +} + +// String returns a human-readable description of this Workspace Tag ID +func (id WorkspaceTagId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Tag: %q", id.TagId), + } + return fmt.Sprintf("Workspace Tag (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/tagoperationlink/id_workspacetag_test.go b/resource-manager/apimanagement/2024-05-01/tagoperationlink/id_workspacetag_test.go new file mode 100644 index 00000000000..942f6f1f0c8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagoperationlink/id_workspacetag_test.go @@ -0,0 +1,372 @@ +package tagoperationlink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceTagId{} + +func TestNewWorkspaceTagID(t *testing.T) { + id := NewWorkspaceTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.TagId != "tagIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'TagId'", id.TagId, "tagIdValue") + } +} + +func TestFormatWorkspaceTagID(t *testing.T) { + actual := NewWorkspaceTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceTagID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceTagId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue", + Expected: &WorkspaceTagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + TagId: "tagIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceTagID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + } +} + +func TestParseWorkspaceTagIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceTagId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue", + Expected: &WorkspaceTagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + TagId: "tagIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS/tAgIdVaLuE", + Expected: &WorkspaceTagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + TagId: "tAgIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS/tAgIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceTagIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + } +} + +func TestSegmentsForWorkspaceTagId(t *testing.T) { + segments := WorkspaceTagId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceTagId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/tagoperationlink/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/tagoperationlink/method_createorupdate.go new file mode 100644 index 00000000000..e306fb5a87c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagoperationlink/method_createorupdate.go @@ -0,0 +1,59 @@ +package tagoperationlink + +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 *TagOperationLinkContract +} + +// CreateOrUpdate ... +func (c TagOperationLinkClient) CreateOrUpdate(ctx context.Context, id OperationLinkId, input TagOperationLinkContract) (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 TagOperationLinkContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagoperationlink/method_delete.go b/resource-manager/apimanagement/2024-05-01/tagoperationlink/method_delete.go new file mode 100644 index 00000000000..bc70a05caaf --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagoperationlink/method_delete.go @@ -0,0 +1,47 @@ +package tagoperationlink + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c TagOperationLinkClient) Delete(ctx context.Context, id OperationLinkId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagoperationlink/method_get.go b/resource-manager/apimanagement/2024-05-01/tagoperationlink/method_get.go new file mode 100644 index 00000000000..9f16e16283d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagoperationlink/method_get.go @@ -0,0 +1,54 @@ +package tagoperationlink + +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 *TagOperationLinkContract +} + +// Get ... +func (c TagOperationLinkClient) Get(ctx context.Context, id OperationLinkId) (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 TagOperationLinkContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagoperationlink/method_listbyproduct.go b/resource-manager/apimanagement/2024-05-01/tagoperationlink/method_listbyproduct.go new file mode 100644 index 00000000000..cee618cdcb6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagoperationlink/method_listbyproduct.go @@ -0,0 +1,141 @@ +package tagoperationlink + +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 ListByProductOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TagOperationLinkContract +} + +type ListByProductCompleteResult struct { + LatestHttpResponse *http.Response + Items []TagOperationLinkContract +} + +type ListByProductOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByProductOperationOptions() ListByProductOperationOptions { + return ListByProductOperationOptions{} +} + +func (o ListByProductOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByProductOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByProductOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByProductCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByProductCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByProduct ... +func (c TagOperationLinkClient) ListByProduct(ctx context.Context, id TagId, options ListByProductOperationOptions) (result ListByProductOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByProductCustomPager{}, + Path: fmt.Sprintf("%s/operationLinks", 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 *[]TagOperationLinkContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByProductComplete retrieves all the results into a single object +func (c TagOperationLinkClient) ListByProductComplete(ctx context.Context, id TagId, options ListByProductOperationOptions) (ListByProductCompleteResult, error) { + return c.ListByProductCompleteMatchingPredicate(ctx, id, options, TagOperationLinkContractOperationPredicate{}) +} + +// ListByProductCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TagOperationLinkClient) ListByProductCompleteMatchingPredicate(ctx context.Context, id TagId, options ListByProductOperationOptions, predicate TagOperationLinkContractOperationPredicate) (result ListByProductCompleteResult, err error) { + items := make([]TagOperationLinkContract, 0) + + resp, err := c.ListByProduct(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByProductCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagoperationlink/method_workspacetagoperationlinkcreateorupdate.go b/resource-manager/apimanagement/2024-05-01/tagoperationlink/method_workspacetagoperationlinkcreateorupdate.go new file mode 100644 index 00000000000..fcb4d980ef4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagoperationlink/method_workspacetagoperationlinkcreateorupdate.go @@ -0,0 +1,59 @@ +package tagoperationlink + +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 WorkspaceTagOperationLinkCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TagOperationLinkContract +} + +// WorkspaceTagOperationLinkCreateOrUpdate ... +func (c TagOperationLinkClient) WorkspaceTagOperationLinkCreateOrUpdate(ctx context.Context, id TagOperationLinkId, input TagOperationLinkContract) (result WorkspaceTagOperationLinkCreateOrUpdateOperationResponse, 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 TagOperationLinkContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagoperationlink/method_workspacetagoperationlinkdelete.go b/resource-manager/apimanagement/2024-05-01/tagoperationlink/method_workspacetagoperationlinkdelete.go new file mode 100644 index 00000000000..b23b6e80b3f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagoperationlink/method_workspacetagoperationlinkdelete.go @@ -0,0 +1,47 @@ +package tagoperationlink + +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 WorkspaceTagOperationLinkDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceTagOperationLinkDelete ... +func (c TagOperationLinkClient) WorkspaceTagOperationLinkDelete(ctx context.Context, id TagOperationLinkId) (result WorkspaceTagOperationLinkDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagoperationlink/method_workspacetagoperationlinkget.go b/resource-manager/apimanagement/2024-05-01/tagoperationlink/method_workspacetagoperationlinkget.go new file mode 100644 index 00000000000..8e90fec49fc --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagoperationlink/method_workspacetagoperationlinkget.go @@ -0,0 +1,54 @@ +package tagoperationlink + +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 WorkspaceTagOperationLinkGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TagOperationLinkContract +} + +// WorkspaceTagOperationLinkGet ... +func (c TagOperationLinkClient) WorkspaceTagOperationLinkGet(ctx context.Context, id TagOperationLinkId) (result WorkspaceTagOperationLinkGetOperationResponse, 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 TagOperationLinkContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagoperationlink/method_workspacetagoperationlinklistbyproduct.go b/resource-manager/apimanagement/2024-05-01/tagoperationlink/method_workspacetagoperationlinklistbyproduct.go new file mode 100644 index 00000000000..46445e555b0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagoperationlink/method_workspacetagoperationlinklistbyproduct.go @@ -0,0 +1,141 @@ +package tagoperationlink + +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 WorkspaceTagOperationLinkListByProductOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TagOperationLinkContract +} + +type WorkspaceTagOperationLinkListByProductCompleteResult struct { + LatestHttpResponse *http.Response + Items []TagOperationLinkContract +} + +type WorkspaceTagOperationLinkListByProductOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultWorkspaceTagOperationLinkListByProductOperationOptions() WorkspaceTagOperationLinkListByProductOperationOptions { + return WorkspaceTagOperationLinkListByProductOperationOptions{} +} + +func (o WorkspaceTagOperationLinkListByProductOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceTagOperationLinkListByProductOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceTagOperationLinkListByProductOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspaceTagOperationLinkListByProductCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceTagOperationLinkListByProductCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceTagOperationLinkListByProduct ... +func (c TagOperationLinkClient) WorkspaceTagOperationLinkListByProduct(ctx context.Context, id WorkspaceTagId, options WorkspaceTagOperationLinkListByProductOperationOptions) (result WorkspaceTagOperationLinkListByProductOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspaceTagOperationLinkListByProductCustomPager{}, + Path: fmt.Sprintf("%s/operationLinks", 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 *[]TagOperationLinkContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceTagOperationLinkListByProductComplete retrieves all the results into a single object +func (c TagOperationLinkClient) WorkspaceTagOperationLinkListByProductComplete(ctx context.Context, id WorkspaceTagId, options WorkspaceTagOperationLinkListByProductOperationOptions) (WorkspaceTagOperationLinkListByProductCompleteResult, error) { + return c.WorkspaceTagOperationLinkListByProductCompleteMatchingPredicate(ctx, id, options, TagOperationLinkContractOperationPredicate{}) +} + +// WorkspaceTagOperationLinkListByProductCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TagOperationLinkClient) WorkspaceTagOperationLinkListByProductCompleteMatchingPredicate(ctx context.Context, id WorkspaceTagId, options WorkspaceTagOperationLinkListByProductOperationOptions, predicate TagOperationLinkContractOperationPredicate) (result WorkspaceTagOperationLinkListByProductCompleteResult, err error) { + items := make([]TagOperationLinkContract, 0) + + resp, err := c.WorkspaceTagOperationLinkListByProduct(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceTagOperationLinkListByProductCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagoperationlink/model_tagoperationlinkcontract.go b/resource-manager/apimanagement/2024-05-01/tagoperationlink/model_tagoperationlinkcontract.go new file mode 100644 index 00000000000..64a37456280 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagoperationlink/model_tagoperationlinkcontract.go @@ -0,0 +1,11 @@ +package tagoperationlink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagOperationLinkContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *TagOperationLinkContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tagoperationlink/model_tagoperationlinkcontractproperties.go b/resource-manager/apimanagement/2024-05-01/tagoperationlink/model_tagoperationlinkcontractproperties.go new file mode 100644 index 00000000000..b9cde67c9b5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagoperationlink/model_tagoperationlinkcontractproperties.go @@ -0,0 +1,8 @@ +package tagoperationlink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagOperationLinkContractProperties struct { + OperationId string `json:"operationId"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tagoperationlink/predicates.go b/resource-manager/apimanagement/2024-05-01/tagoperationlink/predicates.go new file mode 100644 index 00000000000..58320cae00e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagoperationlink/predicates.go @@ -0,0 +1,27 @@ +package tagoperationlink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagOperationLinkContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p TagOperationLinkContractOperationPredicate) Matches(input TagOperationLinkContract) 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/apimanagement/2024-05-01/tagoperationlink/version.go b/resource-manager/apimanagement/2024-05-01/tagoperationlink/version.go new file mode 100644 index 00000000000..3c8811a6a8a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagoperationlink/version.go @@ -0,0 +1,12 @@ +package tagoperationlink + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/tagoperationlink/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/tagproductlink/README.md b/resource-manager/apimanagement/2024-05-01/tagproductlink/README.md new file mode 100644 index 00000000000..5c4267f2ae3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagproductlink/README.md @@ -0,0 +1,160 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tagproductlink` Documentation + +The `tagproductlink` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tagproductlink" +``` + + +### Client Initialization + +```go +client := tagproductlink.NewTagProductLinkClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TagProductLinkClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := tagproductlink.NewProductLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue", "productLinkIdValue") + +payload := tagproductlink.TagProductLinkContract{ + // ... +} + + +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: `TagProductLinkClient.Delete` + +```go +ctx := context.TODO() +id := tagproductlink.NewProductLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue", "productLinkIdValue") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagProductLinkClient.Get` + +```go +ctx := context.TODO() +id := tagproductlink.NewProductLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue", "productLinkIdValue") + +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: `TagProductLinkClient.ListByProduct` + +```go +ctx := context.TODO() +id := tagproductlink.NewTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue") + +// alternatively `client.ListByProduct(ctx, id, tagproductlink.DefaultListByProductOperationOptions())` can be used to do batched pagination +items, err := client.ListByProductComplete(ctx, id, tagproductlink.DefaultListByProductOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `TagProductLinkClient.WorkspaceTagProductLinkCreateOrUpdate` + +```go +ctx := context.TODO() +id := tagproductlink.NewTagProductLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue", "productLinkIdValue") + +payload := tagproductlink.TagProductLinkContract{ + // ... +} + + +read, err := client.WorkspaceTagProductLinkCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagProductLinkClient.WorkspaceTagProductLinkDelete` + +```go +ctx := context.TODO() +id := tagproductlink.NewTagProductLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue", "productLinkIdValue") + +read, err := client.WorkspaceTagProductLinkDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagProductLinkClient.WorkspaceTagProductLinkGet` + +```go +ctx := context.TODO() +id := tagproductlink.NewTagProductLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue", "productLinkIdValue") + +read, err := client.WorkspaceTagProductLinkGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagProductLinkClient.WorkspaceTagProductLinkListByProduct` + +```go +ctx := context.TODO() +id := tagproductlink.NewWorkspaceTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue") + +// alternatively `client.WorkspaceTagProductLinkListByProduct(ctx, id, tagproductlink.DefaultWorkspaceTagProductLinkListByProductOperationOptions())` can be used to do batched pagination +items, err := client.WorkspaceTagProductLinkListByProductComplete(ctx, id, tagproductlink.DefaultWorkspaceTagProductLinkListByProductOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/tagproductlink/client.go b/resource-manager/apimanagement/2024-05-01/tagproductlink/client.go new file mode 100644 index 00000000000..955dda813c9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagproductlink/client.go @@ -0,0 +1,26 @@ +package tagproductlink + +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 TagProductLinkClient struct { + Client *resourcemanager.Client +} + +func NewTagProductLinkClientWithBaseURI(sdkApi sdkEnv.Api) (*TagProductLinkClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "tagproductlink", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TagProductLinkClient: %+v", err) + } + + return &TagProductLinkClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/tagproductlink/id_productlink.go b/resource-manager/apimanagement/2024-05-01/tagproductlink/id_productlink.go new file mode 100644 index 00000000000..ebd018211ce --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagproductlink/id_productlink.go @@ -0,0 +1,148 @@ +package tagproductlink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProductLinkId{}) +} + +var _ resourceids.ResourceId = &ProductLinkId{} + +// ProductLinkId is a struct representing the Resource ID for a Product Link +type ProductLinkId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + TagId string + ProductLinkId string +} + +// NewProductLinkID returns a new ProductLinkId struct +func NewProductLinkID(subscriptionId string, resourceGroupName string, serviceName string, tagId string, productLinkId string) ProductLinkId { + return ProductLinkId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + TagId: tagId, + ProductLinkId: productLinkId, + } +} + +// ParseProductLinkID parses 'input' into a ProductLinkId +func ParseProductLinkID(input string) (*ProductLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductLinkId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProductLinkIDInsensitively parses 'input' case-insensitively into a ProductLinkId +// note: this method should only be used for API response data and not user input +func ParseProductLinkIDInsensitively(input string) (*ProductLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProductLinkId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProductLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProductLinkId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.TagId, ok = input.Parsed["tagId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagId", input) + } + + if id.ProductLinkId, ok = input.Parsed["productLinkId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "productLinkId", input) + } + + return nil +} + +// ValidateProductLinkID checks that 'input' can be parsed as a Product Link ID +func ValidateProductLinkID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseProductLinkID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Product Link ID +func (id ProductLinkId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/tags/%s/productLinks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.TagId, id.ProductLinkId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Product Link ID +func (id ProductLinkId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticTags", "tags", "tags"), + resourceids.UserSpecifiedSegment("tagId", "tagIdValue"), + resourceids.StaticSegment("staticProductLinks", "productLinks", "productLinks"), + resourceids.UserSpecifiedSegment("productLinkId", "productLinkIdValue"), + } +} + +// String returns a human-readable description of this Product Link ID +func (id ProductLinkId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Tag: %q", id.TagId), + fmt.Sprintf("Product Link: %q", id.ProductLinkId), + } + return fmt.Sprintf("Product Link (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/tagproductlink/id_productlink_test.go b/resource-manager/apimanagement/2024-05-01/tagproductlink/id_productlink_test.go new file mode 100644 index 00000000000..0211571c186 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagproductlink/id_productlink_test.go @@ -0,0 +1,372 @@ +package tagproductlink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ProductLinkId{} + +func TestNewProductLinkID(t *testing.T) { + id := NewProductLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue", "productLinkIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.TagId != "tagIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'TagId'", id.TagId, "tagIdValue") + } + + if id.ProductLinkId != "productLinkIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProductLinkId'", id.ProductLinkId, "productLinkIdValue") + } +} + +func TestFormatProductLinkID(t *testing.T) { + actual := NewProductLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue", "productLinkIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/productLinks/productLinkIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProductLinkID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/productLinks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/productLinks/productLinkIdValue", + Expected: &ProductLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + TagId: "tagIdValue", + ProductLinkId: "productLinkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/productLinks/productLinkIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductLinkID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + if actual.ProductLinkId != v.Expected.ProductLinkId { + t.Fatalf("Expected %q but got %q for ProductLinkId", v.Expected.ProductLinkId, actual.ProductLinkId) + } + + } +} + +func TestParseProductLinkIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProductLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS/tAgIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/productLinks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS/tAgIdVaLuE/pRoDuCtLiNkS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/productLinks/productLinkIdValue", + Expected: &ProductLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + TagId: "tagIdValue", + ProductLinkId: "productLinkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/productLinks/productLinkIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS/tAgIdVaLuE/pRoDuCtLiNkS/pRoDuCtLiNkIdVaLuE", + Expected: &ProductLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + TagId: "tAgIdVaLuE", + ProductLinkId: "pRoDuCtLiNkIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS/tAgIdVaLuE/pRoDuCtLiNkS/pRoDuCtLiNkIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProductLinkIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + if actual.ProductLinkId != v.Expected.ProductLinkId { + t.Fatalf("Expected %q but got %q for ProductLinkId", v.Expected.ProductLinkId, actual.ProductLinkId) + } + + } +} + +func TestSegmentsForProductLinkId(t *testing.T) { + segments := ProductLinkId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProductLinkId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/tagproductlink/id_tag.go b/resource-manager/apimanagement/2024-05-01/tagproductlink/id_tag.go new file mode 100644 index 00000000000..4ef3fd4eea3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagproductlink/id_tag.go @@ -0,0 +1,139 @@ +package tagproductlink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TagId{}) +} + +var _ resourceids.ResourceId = &TagId{} + +// TagId is a struct representing the Resource ID for a Tag +type TagId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + TagId string +} + +// NewTagID returns a new TagId struct +func NewTagID(subscriptionId string, resourceGroupName string, serviceName string, tagId string) TagId { + return TagId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + TagId: tagId, + } +} + +// ParseTagID parses 'input' into a TagId +func ParseTagID(input string) (*TagId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTagIDInsensitively parses 'input' case-insensitively into a TagId +// note: this method should only be used for API response data and not user input +func ParseTagIDInsensitively(input string) (*TagId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TagId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.TagId, ok = input.Parsed["tagId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagId", input) + } + + return nil +} + +// ValidateTagID checks that 'input' can be parsed as a Tag ID +func ValidateTagID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseTagID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Tag ID +func (id TagId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/tags/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.TagId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Tag ID +func (id TagId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticTags", "tags", "tags"), + resourceids.UserSpecifiedSegment("tagId", "tagIdValue"), + } +} + +// String returns a human-readable description of this Tag ID +func (id TagId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Tag: %q", id.TagId), + } + return fmt.Sprintf("Tag (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/tagproductlink/id_tag_test.go b/resource-manager/apimanagement/2024-05-01/tagproductlink/id_tag_test.go new file mode 100644 index 00000000000..2119a3ffaf5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagproductlink/id_tag_test.go @@ -0,0 +1,327 @@ +package tagproductlink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TagId{} + +func TestNewTagID(t *testing.T) { + id := NewTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.TagId != "tagIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'TagId'", id.TagId, "tagIdValue") + } +} + +func TestFormatTagID(t *testing.T) { + actual := NewTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "tagIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTagID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue", + Expected: &TagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + TagId: "tagIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + } +} + +func TestParseTagIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue", + Expected: &TagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + TagId: "tagIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tags/tagIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS/tAgIdVaLuE", + Expected: &TagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + TagId: "tAgIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tAgS/tAgIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + } +} + +func TestSegmentsForTagId(t *testing.T) { + segments := TagId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TagId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/tagproductlink/id_tagproductlink.go b/resource-manager/apimanagement/2024-05-01/tagproductlink/id_tagproductlink.go new file mode 100644 index 00000000000..bf8fe163803 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagproductlink/id_tagproductlink.go @@ -0,0 +1,157 @@ +package tagproductlink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TagProductLinkId{}) +} + +var _ resourceids.ResourceId = &TagProductLinkId{} + +// TagProductLinkId is a struct representing the Resource ID for a Tag Product Link +type TagProductLinkId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + TagId string + ProductLinkId string +} + +// NewTagProductLinkID returns a new TagProductLinkId struct +func NewTagProductLinkID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, tagId string, productLinkId string) TagProductLinkId { + return TagProductLinkId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + TagId: tagId, + ProductLinkId: productLinkId, + } +} + +// ParseTagProductLinkID parses 'input' into a TagProductLinkId +func ParseTagProductLinkID(input string) (*TagProductLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagProductLinkId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagProductLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTagProductLinkIDInsensitively parses 'input' case-insensitively into a TagProductLinkId +// note: this method should only be used for API response data and not user input +func ParseTagProductLinkIDInsensitively(input string) (*TagProductLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagProductLinkId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagProductLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TagProductLinkId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.TagId, ok = input.Parsed["tagId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagId", input) + } + + if id.ProductLinkId, ok = input.Parsed["productLinkId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "productLinkId", input) + } + + return nil +} + +// ValidateTagProductLinkID checks that 'input' can be parsed as a Tag Product Link ID +func ValidateTagProductLinkID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseTagProductLinkID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Tag Product Link ID +func (id TagProductLinkId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/tags/%s/productLinks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.TagId, id.ProductLinkId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Tag Product Link ID +func (id TagProductLinkId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticTags", "tags", "tags"), + resourceids.UserSpecifiedSegment("tagId", "tagIdValue"), + resourceids.StaticSegment("staticProductLinks", "productLinks", "productLinks"), + resourceids.UserSpecifiedSegment("productLinkId", "productLinkIdValue"), + } +} + +// String returns a human-readable description of this Tag Product Link ID +func (id TagProductLinkId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Tag: %q", id.TagId), + fmt.Sprintf("Product Link: %q", id.ProductLinkId), + } + return fmt.Sprintf("Tag Product Link (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/tagproductlink/id_tagproductlink_test.go b/resource-manager/apimanagement/2024-05-01/tagproductlink/id_tagproductlink_test.go new file mode 100644 index 00000000000..28434241f4f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagproductlink/id_tagproductlink_test.go @@ -0,0 +1,417 @@ +package tagproductlink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TagProductLinkId{} + +func TestNewTagProductLinkID(t *testing.T) { + id := NewTagProductLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue", "productLinkIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.TagId != "tagIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'TagId'", id.TagId, "tagIdValue") + } + + if id.ProductLinkId != "productLinkIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProductLinkId'", id.ProductLinkId, "productLinkIdValue") + } +} + +func TestFormatTagProductLinkID(t *testing.T) { + actual := NewTagProductLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue", "productLinkIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/productLinks/productLinkIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTagProductLinkID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagProductLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/productLinks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/productLinks/productLinkIdValue", + Expected: &TagProductLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + TagId: "tagIdValue", + ProductLinkId: "productLinkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/productLinks/productLinkIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagProductLinkID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + if actual.ProductLinkId != v.Expected.ProductLinkId { + t.Fatalf("Expected %q but got %q for ProductLinkId", v.Expected.ProductLinkId, actual.ProductLinkId) + } + + } +} + +func TestParseTagProductLinkIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagProductLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS/tAgIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/productLinks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS/tAgIdVaLuE/pRoDuCtLiNkS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/productLinks/productLinkIdValue", + Expected: &TagProductLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + TagId: "tagIdValue", + ProductLinkId: "productLinkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/productLinks/productLinkIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS/tAgIdVaLuE/pRoDuCtLiNkS/pRoDuCtLiNkIdVaLuE", + Expected: &TagProductLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + TagId: "tAgIdVaLuE", + ProductLinkId: "pRoDuCtLiNkIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS/tAgIdVaLuE/pRoDuCtLiNkS/pRoDuCtLiNkIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagProductLinkIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + if actual.ProductLinkId != v.Expected.ProductLinkId { + t.Fatalf("Expected %q but got %q for ProductLinkId", v.Expected.ProductLinkId, actual.ProductLinkId) + } + + } +} + +func TestSegmentsForTagProductLinkId(t *testing.T) { + segments := TagProductLinkId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TagProductLinkId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/tagproductlink/id_workspacetag.go b/resource-manager/apimanagement/2024-05-01/tagproductlink/id_workspacetag.go new file mode 100644 index 00000000000..aab9b9ab186 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagproductlink/id_workspacetag.go @@ -0,0 +1,148 @@ +package tagproductlink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceTagId{}) +} + +var _ resourceids.ResourceId = &WorkspaceTagId{} + +// WorkspaceTagId is a struct representing the Resource ID for a Workspace Tag +type WorkspaceTagId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + TagId string +} + +// NewWorkspaceTagID returns a new WorkspaceTagId struct +func NewWorkspaceTagID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, tagId string) WorkspaceTagId { + return WorkspaceTagId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + TagId: tagId, + } +} + +// ParseWorkspaceTagID parses 'input' into a WorkspaceTagId +func ParseWorkspaceTagID(input string) (*WorkspaceTagId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceTagId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceTagId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceTagIDInsensitively parses 'input' case-insensitively into a WorkspaceTagId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceTagIDInsensitively(input string) (*WorkspaceTagId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceTagId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceTagId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceTagId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.TagId, ok = input.Parsed["tagId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagId", input) + } + + return nil +} + +// ValidateWorkspaceTagID checks that 'input' can be parsed as a Workspace Tag ID +func ValidateWorkspaceTagID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceTagID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Tag ID +func (id WorkspaceTagId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/tags/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.TagId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Tag ID +func (id WorkspaceTagId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + resourceids.StaticSegment("staticTags", "tags", "tags"), + resourceids.UserSpecifiedSegment("tagId", "tagIdValue"), + } +} + +// String returns a human-readable description of this Workspace Tag ID +func (id WorkspaceTagId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Tag: %q", id.TagId), + } + return fmt.Sprintf("Workspace Tag (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/tagproductlink/id_workspacetag_test.go b/resource-manager/apimanagement/2024-05-01/tagproductlink/id_workspacetag_test.go new file mode 100644 index 00000000000..1724a003231 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagproductlink/id_workspacetag_test.go @@ -0,0 +1,372 @@ +package tagproductlink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceTagId{} + +func TestNewWorkspaceTagID(t *testing.T) { + id := NewWorkspaceTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } + + if id.TagId != "tagIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'TagId'", id.TagId, "tagIdValue") + } +} + +func TestFormatWorkspaceTagID(t *testing.T) { + actual := NewWorkspaceTagID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue", "tagIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceTagID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceTagId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue", + Expected: &WorkspaceTagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + TagId: "tagIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceTagID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + } +} + +func TestParseWorkspaceTagIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceTagId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue", + Expected: &WorkspaceTagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + TagId: "tagIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/tags/tagIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS/tAgIdVaLuE", + Expected: &WorkspaceTagId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + TagId: "tAgIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/tAgS/tAgIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceTagIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + if actual.TagId != v.Expected.TagId { + t.Fatalf("Expected %q but got %q for TagId", v.Expected.TagId, actual.TagId) + } + + } +} + +func TestSegmentsForWorkspaceTagId(t *testing.T) { + segments := WorkspaceTagId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceTagId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/tagproductlink/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/tagproductlink/method_createorupdate.go new file mode 100644 index 00000000000..3dde143776e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagproductlink/method_createorupdate.go @@ -0,0 +1,59 @@ +package tagproductlink + +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 *TagProductLinkContract +} + +// CreateOrUpdate ... +func (c TagProductLinkClient) CreateOrUpdate(ctx context.Context, id ProductLinkId, input TagProductLinkContract) (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 TagProductLinkContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagproductlink/method_delete.go b/resource-manager/apimanagement/2024-05-01/tagproductlink/method_delete.go new file mode 100644 index 00000000000..57ec24308da --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagproductlink/method_delete.go @@ -0,0 +1,47 @@ +package tagproductlink + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c TagProductLinkClient) Delete(ctx context.Context, id ProductLinkId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagproductlink/method_get.go b/resource-manager/apimanagement/2024-05-01/tagproductlink/method_get.go new file mode 100644 index 00000000000..8d3e297151d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagproductlink/method_get.go @@ -0,0 +1,54 @@ +package tagproductlink + +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 *TagProductLinkContract +} + +// Get ... +func (c TagProductLinkClient) Get(ctx context.Context, id ProductLinkId) (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 TagProductLinkContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagproductlink/method_listbyproduct.go b/resource-manager/apimanagement/2024-05-01/tagproductlink/method_listbyproduct.go new file mode 100644 index 00000000000..c1d3225b9ab --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagproductlink/method_listbyproduct.go @@ -0,0 +1,141 @@ +package tagproductlink + +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 ListByProductOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TagProductLinkContract +} + +type ListByProductCompleteResult struct { + LatestHttpResponse *http.Response + Items []TagProductLinkContract +} + +type ListByProductOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByProductOperationOptions() ListByProductOperationOptions { + return ListByProductOperationOptions{} +} + +func (o ListByProductOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByProductOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByProductOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByProductCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByProductCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByProduct ... +func (c TagProductLinkClient) ListByProduct(ctx context.Context, id TagId, options ListByProductOperationOptions) (result ListByProductOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByProductCustomPager{}, + Path: fmt.Sprintf("%s/productLinks", 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 *[]TagProductLinkContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByProductComplete retrieves all the results into a single object +func (c TagProductLinkClient) ListByProductComplete(ctx context.Context, id TagId, options ListByProductOperationOptions) (ListByProductCompleteResult, error) { + return c.ListByProductCompleteMatchingPredicate(ctx, id, options, TagProductLinkContractOperationPredicate{}) +} + +// ListByProductCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TagProductLinkClient) ListByProductCompleteMatchingPredicate(ctx context.Context, id TagId, options ListByProductOperationOptions, predicate TagProductLinkContractOperationPredicate) (result ListByProductCompleteResult, err error) { + items := make([]TagProductLinkContract, 0) + + resp, err := c.ListByProduct(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByProductCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagproductlink/method_workspacetagproductlinkcreateorupdate.go b/resource-manager/apimanagement/2024-05-01/tagproductlink/method_workspacetagproductlinkcreateorupdate.go new file mode 100644 index 00000000000..b8d0d74206a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagproductlink/method_workspacetagproductlinkcreateorupdate.go @@ -0,0 +1,59 @@ +package tagproductlink + +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 WorkspaceTagProductLinkCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TagProductLinkContract +} + +// WorkspaceTagProductLinkCreateOrUpdate ... +func (c TagProductLinkClient) WorkspaceTagProductLinkCreateOrUpdate(ctx context.Context, id TagProductLinkId, input TagProductLinkContract) (result WorkspaceTagProductLinkCreateOrUpdateOperationResponse, 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 TagProductLinkContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagproductlink/method_workspacetagproductlinkdelete.go b/resource-manager/apimanagement/2024-05-01/tagproductlink/method_workspacetagproductlinkdelete.go new file mode 100644 index 00000000000..babba52198b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagproductlink/method_workspacetagproductlinkdelete.go @@ -0,0 +1,47 @@ +package tagproductlink + +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 WorkspaceTagProductLinkDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceTagProductLinkDelete ... +func (c TagProductLinkClient) WorkspaceTagProductLinkDelete(ctx context.Context, id TagProductLinkId) (result WorkspaceTagProductLinkDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagproductlink/method_workspacetagproductlinkget.go b/resource-manager/apimanagement/2024-05-01/tagproductlink/method_workspacetagproductlinkget.go new file mode 100644 index 00000000000..97e0f8b09c9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagproductlink/method_workspacetagproductlinkget.go @@ -0,0 +1,54 @@ +package tagproductlink + +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 WorkspaceTagProductLinkGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TagProductLinkContract +} + +// WorkspaceTagProductLinkGet ... +func (c TagProductLinkClient) WorkspaceTagProductLinkGet(ctx context.Context, id TagProductLinkId) (result WorkspaceTagProductLinkGetOperationResponse, 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 TagProductLinkContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagproductlink/method_workspacetagproductlinklistbyproduct.go b/resource-manager/apimanagement/2024-05-01/tagproductlink/method_workspacetagproductlinklistbyproduct.go new file mode 100644 index 00000000000..374d9806a47 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagproductlink/method_workspacetagproductlinklistbyproduct.go @@ -0,0 +1,141 @@ +package tagproductlink + +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 WorkspaceTagProductLinkListByProductOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TagProductLinkContract +} + +type WorkspaceTagProductLinkListByProductCompleteResult struct { + LatestHttpResponse *http.Response + Items []TagProductLinkContract +} + +type WorkspaceTagProductLinkListByProductOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultWorkspaceTagProductLinkListByProductOperationOptions() WorkspaceTagProductLinkListByProductOperationOptions { + return WorkspaceTagProductLinkListByProductOperationOptions{} +} + +func (o WorkspaceTagProductLinkListByProductOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspaceTagProductLinkListByProductOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o WorkspaceTagProductLinkListByProductOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspaceTagProductLinkListByProductCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspaceTagProductLinkListByProductCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspaceTagProductLinkListByProduct ... +func (c TagProductLinkClient) WorkspaceTagProductLinkListByProduct(ctx context.Context, id WorkspaceTagId, options WorkspaceTagProductLinkListByProductOperationOptions) (result WorkspaceTagProductLinkListByProductOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspaceTagProductLinkListByProductCustomPager{}, + Path: fmt.Sprintf("%s/productLinks", 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 *[]TagProductLinkContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceTagProductLinkListByProductComplete retrieves all the results into a single object +func (c TagProductLinkClient) WorkspaceTagProductLinkListByProductComplete(ctx context.Context, id WorkspaceTagId, options WorkspaceTagProductLinkListByProductOperationOptions) (WorkspaceTagProductLinkListByProductCompleteResult, error) { + return c.WorkspaceTagProductLinkListByProductCompleteMatchingPredicate(ctx, id, options, TagProductLinkContractOperationPredicate{}) +} + +// WorkspaceTagProductLinkListByProductCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TagProductLinkClient) WorkspaceTagProductLinkListByProductCompleteMatchingPredicate(ctx context.Context, id WorkspaceTagId, options WorkspaceTagProductLinkListByProductOperationOptions, predicate TagProductLinkContractOperationPredicate) (result WorkspaceTagProductLinkListByProductCompleteResult, err error) { + items := make([]TagProductLinkContract, 0) + + resp, err := c.WorkspaceTagProductLinkListByProduct(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceTagProductLinkListByProductCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagproductlink/model_tagproductlinkcontract.go b/resource-manager/apimanagement/2024-05-01/tagproductlink/model_tagproductlinkcontract.go new file mode 100644 index 00000000000..64f67717ebe --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagproductlink/model_tagproductlinkcontract.go @@ -0,0 +1,11 @@ +package tagproductlink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagProductLinkContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *TagProductLinkContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tagproductlink/model_tagproductlinkcontractproperties.go b/resource-manager/apimanagement/2024-05-01/tagproductlink/model_tagproductlinkcontractproperties.go new file mode 100644 index 00000000000..eb9bc01bc63 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagproductlink/model_tagproductlinkcontractproperties.go @@ -0,0 +1,8 @@ +package tagproductlink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagProductLinkContractProperties struct { + ProductId string `json:"productId"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tagproductlink/predicates.go b/resource-manager/apimanagement/2024-05-01/tagproductlink/predicates.go new file mode 100644 index 00000000000..8dc942b792f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagproductlink/predicates.go @@ -0,0 +1,27 @@ +package tagproductlink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagProductLinkContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p TagProductLinkContractOperationPredicate) Matches(input TagProductLinkContract) 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/apimanagement/2024-05-01/tagproductlink/version.go b/resource-manager/apimanagement/2024-05-01/tagproductlink/version.go new file mode 100644 index 00000000000..743dfe6c487 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagproductlink/version.go @@ -0,0 +1,12 @@ +package tagproductlink + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/tagproductlink/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/tagresource/README.md b/resource-manager/apimanagement/2024-05-01/tagresource/README.md new file mode 100644 index 00000000000..2e8767d322d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagresource/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tagresource` Documentation + +The `tagresource` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tagresource" +``` + + +### Client Initialization + +```go +client := tagresource.NewTagResourceClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TagResourceClient.ListByService` + +```go +ctx := context.TODO() +id := tagresource.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, tagresource.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, tagresource.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/tagresource/client.go b/resource-manager/apimanagement/2024-05-01/tagresource/client.go new file mode 100644 index 00000000000..9a4e989f378 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagresource/client.go @@ -0,0 +1,26 @@ +package tagresource + +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 TagResourceClient struct { + Client *resourcemanager.Client +} + +func NewTagResourceClientWithBaseURI(sdkApi sdkEnv.Api) (*TagResourceClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "tagresource", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TagResourceClient: %+v", err) + } + + return &TagResourceClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/tagresource/constants.go b/resource-manager/apimanagement/2024-05-01/tagresource/constants.go new file mode 100644 index 00000000000..1eee5db0853 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagresource/constants.go @@ -0,0 +1,192 @@ +package tagresource + +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 ApiType string + +const ( + ApiTypeGraphql ApiType = "graphql" + ApiTypeGrpc ApiType = "grpc" + ApiTypeHTTP ApiType = "http" + ApiTypeOdata ApiType = "odata" + ApiTypeSoap ApiType = "soap" + ApiTypeWebsocket ApiType = "websocket" +) + +func PossibleValuesForApiType() []string { + return []string{ + string(ApiTypeGraphql), + string(ApiTypeGrpc), + string(ApiTypeHTTP), + string(ApiTypeOdata), + string(ApiTypeSoap), + string(ApiTypeWebsocket), + } +} + +func (s *ApiType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseApiType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseApiType(input string) (*ApiType, error) { + vals := map[string]ApiType{ + "graphql": ApiTypeGraphql, + "grpc": ApiTypeGrpc, + "http": ApiTypeHTTP, + "odata": ApiTypeOdata, + "soap": ApiTypeSoap, + "websocket": ApiTypeWebsocket, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ApiType(input) + return &out, nil +} + +type BearerTokenSendingMethods string + +const ( + BearerTokenSendingMethodsAuthorizationHeader BearerTokenSendingMethods = "authorizationHeader" + BearerTokenSendingMethodsQuery BearerTokenSendingMethods = "query" +) + +func PossibleValuesForBearerTokenSendingMethods() []string { + return []string{ + string(BearerTokenSendingMethodsAuthorizationHeader), + string(BearerTokenSendingMethodsQuery), + } +} + +func (s *BearerTokenSendingMethods) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBearerTokenSendingMethods(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBearerTokenSendingMethods(input string) (*BearerTokenSendingMethods, error) { + vals := map[string]BearerTokenSendingMethods{ + "authorizationheader": BearerTokenSendingMethodsAuthorizationHeader, + "query": BearerTokenSendingMethodsQuery, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BearerTokenSendingMethods(input) + return &out, nil +} + +type ProductState string + +const ( + ProductStateNotPublished ProductState = "notPublished" + ProductStatePublished ProductState = "published" +) + +func PossibleValuesForProductState() []string { + return []string{ + string(ProductStateNotPublished), + string(ProductStatePublished), + } +} + +func (s *ProductState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProductState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProductState(input string) (*ProductState, error) { + vals := map[string]ProductState{ + "notpublished": ProductStateNotPublished, + "published": ProductStatePublished, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProductState(input) + return &out, nil +} + +type Protocol string + +const ( + ProtocolHTTP Protocol = "http" + ProtocolHTTPS Protocol = "https" + ProtocolWs Protocol = "ws" + ProtocolWss Protocol = "wss" +) + +func PossibleValuesForProtocol() []string { + return []string{ + string(ProtocolHTTP), + string(ProtocolHTTPS), + string(ProtocolWs), + string(ProtocolWss), + } +} + +func (s *Protocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProtocol(input string) (*Protocol, error) { + vals := map[string]Protocol{ + "http": ProtocolHTTP, + "https": ProtocolHTTPS, + "ws": ProtocolWs, + "wss": ProtocolWss, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Protocol(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/tagresource/id_service.go b/resource-manager/apimanagement/2024-05-01/tagresource/id_service.go new file mode 100644 index 00000000000..7a6a2163595 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagresource/id_service.go @@ -0,0 +1,130 @@ +package tagresource + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/tagresource/id_service_test.go b/resource-manager/apimanagement/2024-05-01/tagresource/id_service_test.go new file mode 100644 index 00000000000..c812989db4e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagresource/id_service_test.go @@ -0,0 +1,282 @@ +package tagresource + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/tagresource/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/tagresource/method_listbyservice.go new file mode 100644 index 00000000000..0d880dc6dad --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagresource/method_listbyservice.go @@ -0,0 +1,141 @@ +package tagresource + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TagResourceContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []TagResourceContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c TagResourceClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/tagResources", 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 *[]TagResourceContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c TagResourceClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, TagResourceContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TagResourceClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate TagResourceContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]TagResourceContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tagresource/model_apicontactinformation.go b/resource-manager/apimanagement/2024-05-01/tagresource/model_apicontactinformation.go new file mode 100644 index 00000000000..54238080d10 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagresource/model_apicontactinformation.go @@ -0,0 +1,10 @@ +package tagresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiContactInformation struct { + Email *string `json:"email,omitempty"` + Name *string `json:"name,omitempty"` + Url *string `json:"url,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tagresource/model_apilicenseinformation.go b/resource-manager/apimanagement/2024-05-01/tagresource/model_apilicenseinformation.go new file mode 100644 index 00000000000..9aeafa0caf7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagresource/model_apilicenseinformation.go @@ -0,0 +1,9 @@ +package tagresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiLicenseInformation struct { + Name *string `json:"name,omitempty"` + Url *string `json:"url,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tagresource/model_apitagresourcecontractproperties.go b/resource-manager/apimanagement/2024-05-01/tagresource/model_apitagresourcecontractproperties.go new file mode 100644 index 00000000000..a64045d1ae4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagresource/model_apitagresourcecontractproperties.go @@ -0,0 +1,27 @@ +package tagresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiTagResourceContractProperties struct { + ApiRevision *string `json:"apiRevision,omitempty"` + ApiRevisionDescription *string `json:"apiRevisionDescription,omitempty"` + ApiVersion *string `json:"apiVersion,omitempty"` + ApiVersionDescription *string `json:"apiVersionDescription,omitempty"` + ApiVersionSetId *string `json:"apiVersionSetId,omitempty"` + AuthenticationSettings *AuthenticationSettingsContract `json:"authenticationSettings,omitempty"` + Contact *ApiContactInformation `json:"contact,omitempty"` + Description *string `json:"description,omitempty"` + Id *string `json:"id,omitempty"` + IsCurrent *bool `json:"isCurrent,omitempty"` + IsOnline *bool `json:"isOnline,omitempty"` + License *ApiLicenseInformation `json:"license,omitempty"` + Name *string `json:"name,omitempty"` + Path *string `json:"path,omitempty"` + Protocols *[]Protocol `json:"protocols,omitempty"` + ServiceUrl *string `json:"serviceUrl,omitempty"` + SubscriptionKeyParameterNames *SubscriptionKeyParameterNamesContract `json:"subscriptionKeyParameterNames,omitempty"` + SubscriptionRequired *bool `json:"subscriptionRequired,omitempty"` + TermsOfServiceUrl *string `json:"termsOfServiceUrl,omitempty"` + Type *ApiType `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tagresource/model_authenticationsettingscontract.go b/resource-manager/apimanagement/2024-05-01/tagresource/model_authenticationsettingscontract.go new file mode 100644 index 00000000000..cb0ce9b3392 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagresource/model_authenticationsettingscontract.go @@ -0,0 +1,11 @@ +package tagresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthenticationSettingsContract struct { + OAuth2 *OAuth2AuthenticationSettingsContract `json:"oAuth2,omitempty"` + OAuth2AuthenticationSettings *[]OAuth2AuthenticationSettingsContract `json:"oAuth2AuthenticationSettings,omitempty"` + Openid *OpenIdAuthenticationSettingsContract `json:"openid,omitempty"` + OpenidAuthenticationSettings *[]OpenIdAuthenticationSettingsContract `json:"openidAuthenticationSettings,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tagresource/model_oauth2authenticationsettingscontract.go b/resource-manager/apimanagement/2024-05-01/tagresource/model_oauth2authenticationsettingscontract.go new file mode 100644 index 00000000000..4fce5e8ec6d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagresource/model_oauth2authenticationsettingscontract.go @@ -0,0 +1,9 @@ +package tagresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OAuth2AuthenticationSettingsContract struct { + AuthorizationServerId *string `json:"authorizationServerId,omitempty"` + Scope *string `json:"scope,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tagresource/model_openidauthenticationsettingscontract.go b/resource-manager/apimanagement/2024-05-01/tagresource/model_openidauthenticationsettingscontract.go new file mode 100644 index 00000000000..d89f591d79d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagresource/model_openidauthenticationsettingscontract.go @@ -0,0 +1,9 @@ +package tagresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OpenIdAuthenticationSettingsContract struct { + BearerTokenSendingMethods *[]BearerTokenSendingMethods `json:"bearerTokenSendingMethods,omitempty"` + OpenidProviderId *string `json:"openidProviderId,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tagresource/model_operationtagresourcecontractproperties.go b/resource-manager/apimanagement/2024-05-01/tagresource/model_operationtagresourcecontractproperties.go new file mode 100644 index 00000000000..352ae9c1ce9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagresource/model_operationtagresourcecontractproperties.go @@ -0,0 +1,15 @@ +package tagresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationTagResourceContractProperties struct { + ApiName *string `json:"apiName,omitempty"` + ApiRevision *string `json:"apiRevision,omitempty"` + ApiVersion *string `json:"apiVersion,omitempty"` + Description *string `json:"description,omitempty"` + Id *string `json:"id,omitempty"` + Method *string `json:"method,omitempty"` + Name *string `json:"name,omitempty"` + UrlTemplate *string `json:"urlTemplate,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tagresource/model_producttagresourcecontractproperties.go b/resource-manager/apimanagement/2024-05-01/tagresource/model_producttagresourcecontractproperties.go new file mode 100644 index 00000000000..0763fb01651 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagresource/model_producttagresourcecontractproperties.go @@ -0,0 +1,15 @@ +package tagresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductTagResourceContractProperties struct { + ApprovalRequired *bool `json:"approvalRequired,omitempty"` + Description *string `json:"description,omitempty"` + Id *string `json:"id,omitempty"` + Name string `json:"name"` + State *ProductState `json:"state,omitempty"` + SubscriptionRequired *bool `json:"subscriptionRequired,omitempty"` + SubscriptionsLimit *int64 `json:"subscriptionsLimit,omitempty"` + Terms *string `json:"terms,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tagresource/model_subscriptionkeyparameternamescontract.go b/resource-manager/apimanagement/2024-05-01/tagresource/model_subscriptionkeyparameternamescontract.go new file mode 100644 index 00000000000..bf0c371d8ca --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagresource/model_subscriptionkeyparameternamescontract.go @@ -0,0 +1,9 @@ +package tagresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionKeyParameterNamesContract struct { + Header *string `json:"header,omitempty"` + Query *string `json:"query,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tagresource/model_tagresourcecontract.go b/resource-manager/apimanagement/2024-05-01/tagresource/model_tagresourcecontract.go new file mode 100644 index 00000000000..ec7d624291a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagresource/model_tagresourcecontract.go @@ -0,0 +1,11 @@ +package tagresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagResourceContract struct { + Api *ApiTagResourceContractProperties `json:"api,omitempty"` + Operation *OperationTagResourceContractProperties `json:"operation,omitempty"` + Product *ProductTagResourceContractProperties `json:"product,omitempty"` + Tag TagTagResourceContractProperties `json:"tag"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tagresource/model_tagtagresourcecontractproperties.go b/resource-manager/apimanagement/2024-05-01/tagresource/model_tagtagresourcecontractproperties.go new file mode 100644 index 00000000000..8baa5e85079 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagresource/model_tagtagresourcecontractproperties.go @@ -0,0 +1,9 @@ +package tagresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagTagResourceContractProperties struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tagresource/predicates.go b/resource-manager/apimanagement/2024-05-01/tagresource/predicates.go new file mode 100644 index 00000000000..050c454a735 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagresource/predicates.go @@ -0,0 +1,12 @@ +package tagresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagResourceContractOperationPredicate struct { +} + +func (p TagResourceContractOperationPredicate) Matches(input TagResourceContract) bool { + + return true +} diff --git a/resource-manager/apimanagement/2024-05-01/tagresource/version.go b/resource-manager/apimanagement/2024-05-01/tagresource/version.go new file mode 100644 index 00000000000..877efc3c195 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tagresource/version.go @@ -0,0 +1,12 @@ +package tagresource + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/tagresource/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccess/README.md b/resource-manager/apimanagement/2024-05-01/tenantaccess/README.md new file mode 100644 index 00000000000..e34ff239c82 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccess/README.md @@ -0,0 +1,159 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tenantaccess` Documentation + +The `tenantaccess` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tenantaccess" +``` + + +### Client Initialization + +```go +client := tenantaccess.NewTenantAccessClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TenantAccessClient.Create` + +```go +ctx := context.TODO() +id := tenantaccess.NewAccessID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "access") + +payload := tenantaccess.AccessInformationCreateParameters{ + // ... +} + + +read, err := client.Create(ctx, id, payload, tenantaccess.DefaultCreateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TenantAccessClient.Get` + +```go +ctx := context.TODO() +id := tenantaccess.NewAccessID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "access") + +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: `TenantAccessClient.GetEntityTag` + +```go +ctx := context.TODO() +id := tenantaccess.NewAccessID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "access") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TenantAccessClient.ListByService` + +```go +ctx := context.TODO() +id := tenantaccess.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, tenantaccess.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, tenantaccess.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `TenantAccessClient.ListSecrets` + +```go +ctx := context.TODO() +id := tenantaccess.NewAccessID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "access") + +read, err := client.ListSecrets(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TenantAccessClient.RegeneratePrimaryKey` + +```go +ctx := context.TODO() +id := tenantaccess.NewAccessID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "access") + +read, err := client.RegeneratePrimaryKey(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TenantAccessClient.RegenerateSecondaryKey` + +```go +ctx := context.TODO() +id := tenantaccess.NewAccessID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "access") + +read, err := client.RegenerateSecondaryKey(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TenantAccessClient.Update` + +```go +ctx := context.TODO() +id := tenantaccess.NewAccessID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "access") + +payload := tenantaccess.AccessInformationUpdateParameters{ + // ... +} + + +read, err := client.Update(ctx, id, payload, tenantaccess.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccess/client.go b/resource-manager/apimanagement/2024-05-01/tenantaccess/client.go new file mode 100644 index 00000000000..d36cd27765c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccess/client.go @@ -0,0 +1,26 @@ +package tenantaccess + +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 TenantAccessClient struct { + Client *resourcemanager.Client +} + +func NewTenantAccessClientWithBaseURI(sdkApi sdkEnv.Api) (*TenantAccessClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "tenantaccess", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TenantAccessClient: %+v", err) + } + + return &TenantAccessClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccess/constants.go b/resource-manager/apimanagement/2024-05-01/tenantaccess/constants.go new file mode 100644 index 00000000000..0a9a890aae2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccess/constants.go @@ -0,0 +1,51 @@ +package tenantaccess + +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 AccessIdName string + +const ( + AccessIdNameAccess AccessIdName = "access" + AccessIdNameGitAccess AccessIdName = "gitAccess" +) + +func PossibleValuesForAccessIdName() []string { + return []string{ + string(AccessIdNameAccess), + string(AccessIdNameGitAccess), + } +} + +func (s *AccessIdName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAccessIdName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAccessIdName(input string) (*AccessIdName, error) { + vals := map[string]AccessIdName{ + "access": AccessIdNameAccess, + "gitaccess": AccessIdNameGitAccess, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessIdName(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccess/id_access.go b/resource-manager/apimanagement/2024-05-01/tenantaccess/id_access.go new file mode 100644 index 00000000000..927925f0366 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccess/id_access.go @@ -0,0 +1,147 @@ +package tenantaccess + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AccessId{}) +} + +var _ resourceids.ResourceId = &AccessId{} + +// AccessId is a struct representing the Resource ID for a Access +type AccessId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + AccessName AccessIdName +} + +// NewAccessID returns a new AccessId struct +func NewAccessID(subscriptionId string, resourceGroupName string, serviceName string, accessName AccessIdName) AccessId { + return AccessId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + AccessName: accessName, + } +} + +// ParseAccessID parses 'input' into a AccessId +func ParseAccessID(input string) (*AccessId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccessId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccessId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAccessIDInsensitively parses 'input' case-insensitively into a AccessId +// note: this method should only be used for API response data and not user input +func ParseAccessIDInsensitively(input string) (*AccessId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccessId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccessId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AccessId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if v, ok := input.Parsed["accessName"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accessName", input) + } + + accessName, err := parseAccessIdName(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.AccessName = *accessName + } + + return nil +} + +// ValidateAccessID checks that 'input' can be parsed as a Access ID +func ValidateAccessID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseAccessID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Access ID +func (id AccessId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/tenant/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, string(id.AccessName)) +} + +// Segments returns a slice of Resource ID Segments which comprise this Access ID +func (id AccessId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticTenant", "tenant", "tenant"), + resourceids.ConstantSegment("accessName", PossibleValuesForAccessIdName(), "access"), + } +} + +// String returns a human-readable description of this Access ID +func (id AccessId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Access Name: %q", string(id.AccessName)), + } + return fmt.Sprintf("Access (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccess/id_access_test.go b/resource-manager/apimanagement/2024-05-01/tenantaccess/id_access_test.go new file mode 100644 index 00000000000..ed3342ac30f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccess/id_access_test.go @@ -0,0 +1,327 @@ +package tenantaccess + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AccessId{} + +func TestNewAccessID(t *testing.T) { + id := NewAccessID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "access") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.AccessName != "access" { + t.Fatalf("Expected %q but got %q for Segment 'AccessName'", id.AccessName, "access") + } +} + +func TestFormatAccessID(t *testing.T) { + actual := NewAccessID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "access").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tenant/access" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAccessID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccessId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tenant", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tenant/access", + Expected: &AccessId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + AccessName: "access", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tenant/access/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccessID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.AccessName != v.Expected.AccessName { + t.Fatalf("Expected %q but got %q for AccessName", v.Expected.AccessName, actual.AccessName) + } + + } +} + +func TestParseAccessIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccessId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tenant", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tEnAnT", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tenant/access", + Expected: &AccessId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + AccessName: "access", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tenant/access/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tEnAnT/aCcEsS", + Expected: &AccessId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + AccessName: "access", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tEnAnT/aCcEsS/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccessIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.AccessName != v.Expected.AccessName { + t.Fatalf("Expected %q but got %q for AccessName", v.Expected.AccessName, actual.AccessName) + } + + } +} + +func TestSegmentsForAccessId(t *testing.T) { + segments := AccessId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AccessId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccess/id_service.go b/resource-manager/apimanagement/2024-05-01/tenantaccess/id_service.go new file mode 100644 index 00000000000..6dbbad41263 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccess/id_service.go @@ -0,0 +1,130 @@ +package tenantaccess + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccess/id_service_test.go b/resource-manager/apimanagement/2024-05-01/tenantaccess/id_service_test.go new file mode 100644 index 00000000000..e994cd13c2b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccess/id_service_test.go @@ -0,0 +1,282 @@ +package tenantaccess + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccess/method_create.go b/resource-manager/apimanagement/2024-05-01/tenantaccess/method_create.go new file mode 100644 index 00000000000..73ced417651 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccess/method_create.go @@ -0,0 +1,87 @@ +package tenantaccess + +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 CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AccessInformationContract +} + +type CreateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOperationOptions() CreateOperationOptions { + return CreateOperationOptions{} +} + +func (o CreateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Create ... +func (c TenantAccessClient) Create(ctx context.Context, id AccessId, input AccessInformationCreateParameters, options CreateOperationOptions) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 AccessInformationContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccess/method_get.go b/resource-manager/apimanagement/2024-05-01/tenantaccess/method_get.go new file mode 100644 index 00000000000..88298263510 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccess/method_get.go @@ -0,0 +1,54 @@ +package tenantaccess + +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 *AccessInformationContract +} + +// Get ... +func (c TenantAccessClient) Get(ctx context.Context, id AccessId) (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 AccessInformationContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccess/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/tenantaccess/method_getentitytag.go new file mode 100644 index 00000000000..d1d42ee00fd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccess/method_getentitytag.go @@ -0,0 +1,46 @@ +package tenantaccess + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c TenantAccessClient) GetEntityTag(ctx context.Context, id AccessId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccess/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/tenantaccess/method_listbyservice.go new file mode 100644 index 00000000000..541de46f891 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccess/method_listbyservice.go @@ -0,0 +1,133 @@ +package tenantaccess + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AccessInformationContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []AccessInformationContract +} + +type ListByServiceOperationOptions struct { + Filter *string +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c TenantAccessClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/tenant", 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 *[]AccessInformationContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c TenantAccessClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, AccessInformationContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TenantAccessClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate AccessInformationContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]AccessInformationContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccess/method_listsecrets.go b/resource-manager/apimanagement/2024-05-01/tenantaccess/method_listsecrets.go new file mode 100644 index 00000000000..237989384de --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccess/method_listsecrets.go @@ -0,0 +1,55 @@ +package tenantaccess + +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 ListSecretsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AccessInformationSecretsContract +} + +// ListSecrets ... +func (c TenantAccessClient) ListSecrets(ctx context.Context, id AccessId) (result ListSecretsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listSecrets", 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 AccessInformationSecretsContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccess/method_regenerateprimarykey.go b/resource-manager/apimanagement/2024-05-01/tenantaccess/method_regenerateprimarykey.go new file mode 100644 index 00000000000..6d6aa0f1ccf --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccess/method_regenerateprimarykey.go @@ -0,0 +1,47 @@ +package tenantaccess + +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 RegeneratePrimaryKeyOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// RegeneratePrimaryKey ... +func (c TenantAccessClient) RegeneratePrimaryKey(ctx context.Context, id AccessId) (result RegeneratePrimaryKeyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/regeneratePrimaryKey", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccess/method_regeneratesecondarykey.go b/resource-manager/apimanagement/2024-05-01/tenantaccess/method_regeneratesecondarykey.go new file mode 100644 index 00000000000..0fd0b8fd296 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccess/method_regeneratesecondarykey.go @@ -0,0 +1,47 @@ +package tenantaccess + +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 RegenerateSecondaryKeyOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// RegenerateSecondaryKey ... +func (c TenantAccessClient) RegenerateSecondaryKey(ctx context.Context, id AccessId) (result RegenerateSecondaryKeyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/regenerateSecondaryKey", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccess/method_update.go b/resource-manager/apimanagement/2024-05-01/tenantaccess/method_update.go new file mode 100644 index 00000000000..73793de2965 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccess/method_update.go @@ -0,0 +1,87 @@ +package tenantaccess + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AccessInformationContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c TenantAccessClient) Update(ctx context.Context, id AccessId, input AccessInformationUpdateParameters, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 AccessInformationContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccess/model_accessinformationcontract.go b/resource-manager/apimanagement/2024-05-01/tenantaccess/model_accessinformationcontract.go new file mode 100644 index 00000000000..3ad35991bed --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccess/model_accessinformationcontract.go @@ -0,0 +1,11 @@ +package tenantaccess + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessInformationContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AccessInformationContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccess/model_accessinformationcontractproperties.go b/resource-manager/apimanagement/2024-05-01/tenantaccess/model_accessinformationcontractproperties.go new file mode 100644 index 00000000000..7a4c2313293 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccess/model_accessinformationcontractproperties.go @@ -0,0 +1,10 @@ +package tenantaccess + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessInformationContractProperties struct { + Enabled *bool `json:"enabled,omitempty"` + Id *string `json:"id,omitempty"` + PrincipalId *string `json:"principalId,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccess/model_accessinformationcreateparameterproperties.go b/resource-manager/apimanagement/2024-05-01/tenantaccess/model_accessinformationcreateparameterproperties.go new file mode 100644 index 00000000000..09005518990 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccess/model_accessinformationcreateparameterproperties.go @@ -0,0 +1,11 @@ +package tenantaccess + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessInformationCreateParameterProperties struct { + Enabled *bool `json:"enabled,omitempty"` + PrimaryKey *string `json:"primaryKey,omitempty"` + PrincipalId *string `json:"principalId,omitempty"` + SecondaryKey *string `json:"secondaryKey,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccess/model_accessinformationcreateparameters.go b/resource-manager/apimanagement/2024-05-01/tenantaccess/model_accessinformationcreateparameters.go new file mode 100644 index 00000000000..0f13f9d72b9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccess/model_accessinformationcreateparameters.go @@ -0,0 +1,8 @@ +package tenantaccess + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessInformationCreateParameters struct { + Properties *AccessInformationCreateParameterProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccess/model_accessinformationsecretscontract.go b/resource-manager/apimanagement/2024-05-01/tenantaccess/model_accessinformationsecretscontract.go new file mode 100644 index 00000000000..9ec1b2c9b42 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccess/model_accessinformationsecretscontract.go @@ -0,0 +1,12 @@ +package tenantaccess + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessInformationSecretsContract struct { + Enabled *bool `json:"enabled,omitempty"` + Id *string `json:"id,omitempty"` + PrimaryKey *string `json:"primaryKey,omitempty"` + PrincipalId *string `json:"principalId,omitempty"` + SecondaryKey *string `json:"secondaryKey,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccess/model_accessinformationupdateparameterproperties.go b/resource-manager/apimanagement/2024-05-01/tenantaccess/model_accessinformationupdateparameterproperties.go new file mode 100644 index 00000000000..30382f1f637 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccess/model_accessinformationupdateparameterproperties.go @@ -0,0 +1,8 @@ +package tenantaccess + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessInformationUpdateParameterProperties struct { + Enabled *bool `json:"enabled,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccess/model_accessinformationupdateparameters.go b/resource-manager/apimanagement/2024-05-01/tenantaccess/model_accessinformationupdateparameters.go new file mode 100644 index 00000000000..33de23ecca0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccess/model_accessinformationupdateparameters.go @@ -0,0 +1,8 @@ +package tenantaccess + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessInformationUpdateParameters struct { + Properties *AccessInformationUpdateParameterProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccess/predicates.go b/resource-manager/apimanagement/2024-05-01/tenantaccess/predicates.go new file mode 100644 index 00000000000..309dabec476 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccess/predicates.go @@ -0,0 +1,27 @@ +package tenantaccess + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessInformationContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AccessInformationContractOperationPredicate) Matches(input AccessInformationContract) 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/apimanagement/2024-05-01/tenantaccess/version.go b/resource-manager/apimanagement/2024-05-01/tenantaccess/version.go new file mode 100644 index 00000000000..fbd631c5442 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccess/version.go @@ -0,0 +1,12 @@ +package tenantaccess + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/tenantaccess/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccessgit/client.go b/resource-manager/apimanagement/2024-05-01/tenantaccessgit/client.go new file mode 100644 index 00000000000..1540a8d6df5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccessgit/client.go @@ -0,0 +1,26 @@ +package tenantaccessgit + +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 TenantAccessGitClient struct { + Client *resourcemanager.Client +} + +func NewTenantAccessGitClientWithBaseURI(sdkApi sdkEnv.Api) (*TenantAccessGitClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "tenantaccessgit", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TenantAccessGitClient: %+v", err) + } + + return &TenantAccessGitClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccessgit/constants.go b/resource-manager/apimanagement/2024-05-01/tenantaccessgit/constants.go new file mode 100644 index 00000000000..0423218f1c5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccessgit/constants.go @@ -0,0 +1,51 @@ +package tenantaccessgit + +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 AccessIdName string + +const ( + AccessIdNameAccess AccessIdName = "access" + AccessIdNameGitAccess AccessIdName = "gitAccess" +) + +func PossibleValuesForAccessIdName() []string { + return []string{ + string(AccessIdNameAccess), + string(AccessIdNameGitAccess), + } +} + +func (s *AccessIdName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAccessIdName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAccessIdName(input string) (*AccessIdName, error) { + vals := map[string]AccessIdName{ + "access": AccessIdNameAccess, + "gitaccess": AccessIdNameGitAccess, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessIdName(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccessgit/id_access.go b/resource-manager/apimanagement/2024-05-01/tenantaccessgit/id_access.go new file mode 100644 index 00000000000..c4c17575eda --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccessgit/id_access.go @@ -0,0 +1,147 @@ +package tenantaccessgit + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AccessId{}) +} + +var _ resourceids.ResourceId = &AccessId{} + +// AccessId is a struct representing the Resource ID for a Access +type AccessId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + AccessName AccessIdName +} + +// NewAccessID returns a new AccessId struct +func NewAccessID(subscriptionId string, resourceGroupName string, serviceName string, accessName AccessIdName) AccessId { + return AccessId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + AccessName: accessName, + } +} + +// ParseAccessID parses 'input' into a AccessId +func ParseAccessID(input string) (*AccessId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccessId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccessId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAccessIDInsensitively parses 'input' case-insensitively into a AccessId +// note: this method should only be used for API response data and not user input +func ParseAccessIDInsensitively(input string) (*AccessId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccessId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccessId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AccessId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if v, ok := input.Parsed["accessName"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accessName", input) + } + + accessName, err := parseAccessIdName(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.AccessName = *accessName + } + + return nil +} + +// ValidateAccessID checks that 'input' can be parsed as a Access ID +func ValidateAccessID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseAccessID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Access ID +func (id AccessId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/tenant/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, string(id.AccessName)) +} + +// Segments returns a slice of Resource ID Segments which comprise this Access ID +func (id AccessId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticTenant", "tenant", "tenant"), + resourceids.ConstantSegment("accessName", PossibleValuesForAccessIdName(), "access"), + } +} + +// String returns a human-readable description of this Access ID +func (id AccessId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Access Name: %q", string(id.AccessName)), + } + return fmt.Sprintf("Access (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccessgit/id_access_test.go b/resource-manager/apimanagement/2024-05-01/tenantaccessgit/id_access_test.go new file mode 100644 index 00000000000..664ec1bec70 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccessgit/id_access_test.go @@ -0,0 +1,327 @@ +package tenantaccessgit + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AccessId{} + +func TestNewAccessID(t *testing.T) { + id := NewAccessID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "access") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.AccessName != "access" { + t.Fatalf("Expected %q but got %q for Segment 'AccessName'", id.AccessName, "access") + } +} + +func TestFormatAccessID(t *testing.T) { + actual := NewAccessID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "access").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tenant/access" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAccessID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccessId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tenant", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tenant/access", + Expected: &AccessId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + AccessName: "access", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tenant/access/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccessID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.AccessName != v.Expected.AccessName { + t.Fatalf("Expected %q but got %q for AccessName", v.Expected.AccessName, actual.AccessName) + } + + } +} + +func TestParseAccessIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccessId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tenant", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tEnAnT", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tenant/access", + Expected: &AccessId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + AccessName: "access", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/tenant/access/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tEnAnT/aCcEsS", + Expected: &AccessId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + AccessName: "access", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/tEnAnT/aCcEsS/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccessIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.AccessName != v.Expected.AccessName { + t.Fatalf("Expected %q but got %q for AccessName", v.Expected.AccessName, actual.AccessName) + } + + } +} + +func TestSegmentsForAccessId(t *testing.T) { + segments := AccessId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AccessId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccessgit/method_regenerateprimarykey.go b/resource-manager/apimanagement/2024-05-01/tenantaccessgit/method_regenerateprimarykey.go new file mode 100644 index 00000000000..5b6c503576f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccessgit/method_regenerateprimarykey.go @@ -0,0 +1,47 @@ +package tenantaccessgit + +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 RegeneratePrimaryKeyOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// RegeneratePrimaryKey ... +func (c TenantAccessGitClient) RegeneratePrimaryKey(ctx context.Context, id AccessId) (result RegeneratePrimaryKeyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/git/regeneratePrimaryKey", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccessgit/method_regeneratesecondarykey.go b/resource-manager/apimanagement/2024-05-01/tenantaccessgit/method_regeneratesecondarykey.go new file mode 100644 index 00000000000..fa55bca8deb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccessgit/method_regeneratesecondarykey.go @@ -0,0 +1,47 @@ +package tenantaccessgit + +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 RegenerateSecondaryKeyOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// RegenerateSecondaryKey ... +func (c TenantAccessGitClient) RegenerateSecondaryKey(ctx context.Context, id AccessId) (result RegenerateSecondaryKeyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/git/regenerateSecondaryKey", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantaccessgit/version.go b/resource-manager/apimanagement/2024-05-01/tenantaccessgit/version.go new file mode 100644 index 00000000000..4f69982fc74 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantaccessgit/version.go @@ -0,0 +1,12 @@ +package tenantaccessgit + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/tenantaccessgit/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfiguration/README.md b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/README.md new file mode 100644 index 00000000000..5d27c06acc9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/README.md @@ -0,0 +1,71 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tenantconfiguration` Documentation + +The `tenantconfiguration` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tenantconfiguration" +``` + + +### Client Initialization + +```go +client := tenantconfiguration.NewTenantConfigurationClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TenantConfigurationClient.Deploy` + +```go +ctx := context.TODO() +id := tenantconfiguration.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +payload := tenantconfiguration.DeployConfigurationParameters{ + // ... +} + + +if err := client.DeployThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `TenantConfigurationClient.Save` + +```go +ctx := context.TODO() +id := tenantconfiguration.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +payload := tenantconfiguration.SaveConfigurationParameter{ + // ... +} + + +if err := client.SaveThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `TenantConfigurationClient.Validate` + +```go +ctx := context.TODO() +id := tenantconfiguration.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +payload := tenantconfiguration.DeployConfigurationParameters{ + // ... +} + + +if err := client.ValidateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfiguration/client.go b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/client.go new file mode 100644 index 00000000000..0251dfc8eb5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/client.go @@ -0,0 +1,26 @@ +package tenantconfiguration + +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 TenantConfigurationClient struct { + Client *resourcemanager.Client +} + +func NewTenantConfigurationClientWithBaseURI(sdkApi sdkEnv.Api) (*TenantConfigurationClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "tenantconfiguration", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TenantConfigurationClient: %+v", err) + } + + return &TenantConfigurationClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfiguration/constants.go b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/constants.go new file mode 100644 index 00000000000..c896fa35bce --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/constants.go @@ -0,0 +1,57 @@ +package tenantconfiguration + +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 AsyncOperationStatus string + +const ( + AsyncOperationStatusFailed AsyncOperationStatus = "Failed" + AsyncOperationStatusInProgress AsyncOperationStatus = "InProgress" + AsyncOperationStatusStarted AsyncOperationStatus = "Started" + AsyncOperationStatusSucceeded AsyncOperationStatus = "Succeeded" +) + +func PossibleValuesForAsyncOperationStatus() []string { + return []string{ + string(AsyncOperationStatusFailed), + string(AsyncOperationStatusInProgress), + string(AsyncOperationStatusStarted), + string(AsyncOperationStatusSucceeded), + } +} + +func (s *AsyncOperationStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAsyncOperationStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAsyncOperationStatus(input string) (*AsyncOperationStatus, error) { + vals := map[string]AsyncOperationStatus{ + "failed": AsyncOperationStatusFailed, + "inprogress": AsyncOperationStatusInProgress, + "started": AsyncOperationStatusStarted, + "succeeded": AsyncOperationStatusSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AsyncOperationStatus(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfiguration/id_service.go b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/id_service.go new file mode 100644 index 00000000000..0a039a17bc1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/id_service.go @@ -0,0 +1,130 @@ +package tenantconfiguration + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfiguration/id_service_test.go b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/id_service_test.go new file mode 100644 index 00000000000..968f163e208 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/id_service_test.go @@ -0,0 +1,282 @@ +package tenantconfiguration + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfiguration/method_deploy.go b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/method_deploy.go new file mode 100644 index 00000000000..c867cd9d13f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/method_deploy.go @@ -0,0 +1,75 @@ +package tenantconfiguration + +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 DeployOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *OperationResultContract +} + +// Deploy ... +func (c TenantConfigurationClient) Deploy(ctx context.Context, id ServiceId, input DeployConfigurationParameters) (result DeployOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/tenant/configuration/deploy", 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 +} + +// DeployThenPoll performs Deploy then polls until it's completed +func (c TenantConfigurationClient) DeployThenPoll(ctx context.Context, id ServiceId, input DeployConfigurationParameters) error { + result, err := c.Deploy(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Deploy: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Deploy: %+v", err) + } + + return nil +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfiguration/method_save.go b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/method_save.go new file mode 100644 index 00000000000..7619fb303ce --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/method_save.go @@ -0,0 +1,75 @@ +package tenantconfiguration + +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 SaveOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *OperationResultContract +} + +// Save ... +func (c TenantConfigurationClient) Save(ctx context.Context, id ServiceId, input SaveConfigurationParameter) (result SaveOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/tenant/configuration/save", 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 +} + +// SaveThenPoll performs Save then polls until it's completed +func (c TenantConfigurationClient) SaveThenPoll(ctx context.Context, id ServiceId, input SaveConfigurationParameter) error { + result, err := c.Save(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Save: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Save: %+v", err) + } + + return nil +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfiguration/method_validate.go b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/method_validate.go new file mode 100644 index 00000000000..ef7705cef92 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/method_validate.go @@ -0,0 +1,75 @@ +package tenantconfiguration + +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 ValidateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *OperationResultContract +} + +// Validate ... +func (c TenantConfigurationClient) Validate(ctx context.Context, id ServiceId, input DeployConfigurationParameters) (result ValidateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/tenant/configuration/validate", 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 +} + +// ValidateThenPoll performs Validate then polls until it's completed +func (c TenantConfigurationClient) ValidateThenPoll(ctx context.Context, id ServiceId, input DeployConfigurationParameters) error { + result, err := c.Validate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Validate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Validate: %+v", err) + } + + return nil +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_deployconfigurationparameterproperties.go b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_deployconfigurationparameterproperties.go new file mode 100644 index 00000000000..88acd8033f1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_deployconfigurationparameterproperties.go @@ -0,0 +1,9 @@ +package tenantconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeployConfigurationParameterProperties struct { + Branch string `json:"branch"` + Force *bool `json:"force,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_deployconfigurationparameters.go b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_deployconfigurationparameters.go new file mode 100644 index 00000000000..2f9cf5696d3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_deployconfigurationparameters.go @@ -0,0 +1,8 @@ +package tenantconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeployConfigurationParameters struct { + Properties *DeployConfigurationParameterProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_errorfieldcontract.go b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_errorfieldcontract.go new file mode 100644 index 00000000000..01a75e3527f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_errorfieldcontract.go @@ -0,0 +1,10 @@ +package tenantconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorFieldContract struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_errorresponsebody.go b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_errorresponsebody.go new file mode 100644 index 00000000000..7584f3f9ff7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_errorresponsebody.go @@ -0,0 +1,10 @@ +package tenantconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorResponseBody struct { + Code *string `json:"code,omitempty"` + Details *[]ErrorFieldContract `json:"details,omitempty"` + Message *string `json:"message,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_operationresultcontract.go b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_operationresultcontract.go new file mode 100644 index 00000000000..4833f406c53 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_operationresultcontract.go @@ -0,0 +1,11 @@ +package tenantconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationResultContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *OperationResultContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_operationresultcontractproperties.go b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_operationresultcontractproperties.go new file mode 100644 index 00000000000..a52cec456f7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_operationresultcontractproperties.go @@ -0,0 +1,44 @@ +package tenantconfiguration + +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 OperationResultContractProperties struct { + ActionLog *[]OperationResultLogItemContract `json:"actionLog,omitempty"` + Error *ErrorResponseBody `json:"error,omitempty"` + Id *string `json:"id,omitempty"` + ResultInfo *string `json:"resultInfo,omitempty"` + Started *string `json:"started,omitempty"` + Status *AsyncOperationStatus `json:"status,omitempty"` + Updated *string `json:"updated,omitempty"` +} + +func (o *OperationResultContractProperties) GetStartedAsTime() (*time.Time, error) { + if o.Started == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Started, "2006-01-02T15:04:05Z07:00") +} + +func (o *OperationResultContractProperties) SetStartedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Started = &formatted +} + +func (o *OperationResultContractProperties) GetUpdatedAsTime() (*time.Time, error) { + if o.Updated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Updated, "2006-01-02T15:04:05Z07:00") +} + +func (o *OperationResultContractProperties) SetUpdatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Updated = &formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_operationresultlogitemcontract.go b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_operationresultlogitemcontract.go new file mode 100644 index 00000000000..b06264de0ae --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_operationresultlogitemcontract.go @@ -0,0 +1,10 @@ +package tenantconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationResultLogItemContract struct { + Action *string `json:"action,omitempty"` + ObjectKey *string `json:"objectKey,omitempty"` + ObjectType *string `json:"objectType,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_saveconfigurationparameter.go b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_saveconfigurationparameter.go new file mode 100644 index 00000000000..6a571ee24d7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_saveconfigurationparameter.go @@ -0,0 +1,8 @@ +package tenantconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SaveConfigurationParameter struct { + Properties *SaveConfigurationParameterProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_saveconfigurationparameterproperties.go b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_saveconfigurationparameterproperties.go new file mode 100644 index 00000000000..b2eac04fc96 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/model_saveconfigurationparameterproperties.go @@ -0,0 +1,9 @@ +package tenantconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SaveConfigurationParameterProperties struct { + Branch string `json:"branch"` + Force *bool `json:"force,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfiguration/version.go b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/version.go new file mode 100644 index 00000000000..640f7d0757e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfiguration/version.go @@ -0,0 +1,12 @@ +package tenantconfiguration + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/tenantconfiguration/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate/README.md b/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate/README.md new file mode 100644 index 00000000000..8e39cf3f062 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate` Documentation + +The `tenantconfigurationsyncstate` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate" +``` + + +### Client Initialization + +```go +client := tenantconfigurationsyncstate.NewTenantConfigurationSyncStateClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TenantConfigurationSyncStateClient.TenantConfigurationGetSyncState` + +```go +ctx := context.TODO() +id := tenantconfigurationsyncstate.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +read, err := client.TenantConfigurationGetSyncState(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/apimanagement/2024-05-01/tenantconfigurationsyncstate/client.go b/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate/client.go new file mode 100644 index 00000000000..f79f21d0f2c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate/client.go @@ -0,0 +1,26 @@ +package tenantconfigurationsyncstate + +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 TenantConfigurationSyncStateClient struct { + Client *resourcemanager.Client +} + +func NewTenantConfigurationSyncStateClientWithBaseURI(sdkApi sdkEnv.Api) (*TenantConfigurationSyncStateClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "tenantconfigurationsyncstate", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TenantConfigurationSyncStateClient: %+v", err) + } + + return &TenantConfigurationSyncStateClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate/id_service.go b/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate/id_service.go new file mode 100644 index 00000000000..354cdf503e1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate/id_service.go @@ -0,0 +1,130 @@ +package tenantconfigurationsyncstate + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate/id_service_test.go b/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate/id_service_test.go new file mode 100644 index 00000000000..d1d0cedbf69 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate/id_service_test.go @@ -0,0 +1,282 @@ +package tenantconfigurationsyncstate + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate/method_tenantconfigurationgetsyncstate.go b/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate/method_tenantconfigurationgetsyncstate.go new file mode 100644 index 00000000000..fee9e2d3374 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate/method_tenantconfigurationgetsyncstate.go @@ -0,0 +1,55 @@ +package tenantconfigurationsyncstate + +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 TenantConfigurationGetSyncStateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TenantConfigurationSyncStateContract +} + +// TenantConfigurationGetSyncState ... +func (c TenantConfigurationSyncStateClient) TenantConfigurationGetSyncState(ctx context.Context, id ServiceId) (result TenantConfigurationGetSyncStateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/tenant/configuration/syncState", 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 TenantConfigurationSyncStateContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate/model_tenantconfigurationsyncstatecontract.go b/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate/model_tenantconfigurationsyncstatecontract.go new file mode 100644 index 00000000000..62265d641cb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate/model_tenantconfigurationsyncstatecontract.go @@ -0,0 +1,11 @@ +package tenantconfigurationsyncstate + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TenantConfigurationSyncStateContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *TenantConfigurationSyncStateContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate/model_tenantconfigurationsyncstatecontractproperties.go b/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate/model_tenantconfigurationsyncstatecontractproperties.go new file mode 100644 index 00000000000..8d35353de54 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate/model_tenantconfigurationsyncstatecontractproperties.go @@ -0,0 +1,45 @@ +package tenantconfigurationsyncstate + +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 TenantConfigurationSyncStateContractProperties struct { + Branch *string `json:"branch,omitempty"` + CommitId *string `json:"commitId,omitempty"` + ConfigurationChangeDate *string `json:"configurationChangeDate,omitempty"` + IsExport *bool `json:"isExport,omitempty"` + IsGitEnabled *bool `json:"isGitEnabled,omitempty"` + IsSynced *bool `json:"isSynced,omitempty"` + LastOperationId *string `json:"lastOperationId,omitempty"` + SyncDate *string `json:"syncDate,omitempty"` +} + +func (o *TenantConfigurationSyncStateContractProperties) GetConfigurationChangeDateAsTime() (*time.Time, error) { + if o.ConfigurationChangeDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ConfigurationChangeDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *TenantConfigurationSyncStateContractProperties) SetConfigurationChangeDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ConfigurationChangeDate = &formatted +} + +func (o *TenantConfigurationSyncStateContractProperties) GetSyncDateAsTime() (*time.Time, error) { + if o.SyncDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.SyncDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *TenantConfigurationSyncStateContractProperties) SetSyncDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.SyncDate = &formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate/version.go b/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate/version.go new file mode 100644 index 00000000000..38ebef3f3e3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantconfigurationsyncstate/version.go @@ -0,0 +1,12 @@ +package tenantconfigurationsyncstate + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/tenantconfigurationsyncstate/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantsettings/README.md b/resource-manager/apimanagement/2024-05-01/tenantsettings/README.md new file mode 100644 index 00000000000..311ab5ae09d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantsettings/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tenantsettings` Documentation + +The `tenantsettings` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/tenantsettings" +``` + + +### Client Initialization + +```go +client := tenantsettings.NewTenantSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TenantSettingsClient.Get` + +```go +ctx := context.TODO() +id := tenantsettings.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +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: `TenantSettingsClient.ListByService` + +```go +ctx := context.TODO() +id := tenantsettings.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, tenantsettings.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, tenantsettings.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/tenantsettings/client.go b/resource-manager/apimanagement/2024-05-01/tenantsettings/client.go new file mode 100644 index 00000000000..db0f8f815eb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantsettings/client.go @@ -0,0 +1,26 @@ +package tenantsettings + +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 TenantSettingsClient struct { + Client *resourcemanager.Client +} + +func NewTenantSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*TenantSettingsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "tenantsettings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TenantSettingsClient: %+v", err) + } + + return &TenantSettingsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantsettings/id_service.go b/resource-manager/apimanagement/2024-05-01/tenantsettings/id_service.go new file mode 100644 index 00000000000..68a0c265a26 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantsettings/id_service.go @@ -0,0 +1,130 @@ +package tenantsettings + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantsettings/id_service_test.go b/resource-manager/apimanagement/2024-05-01/tenantsettings/id_service_test.go new file mode 100644 index 00000000000..711d3156790 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantsettings/id_service_test.go @@ -0,0 +1,282 @@ +package tenantsettings + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantsettings/method_get.go b/resource-manager/apimanagement/2024-05-01/tenantsettings/method_get.go new file mode 100644 index 00000000000..40a9e01b321 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantsettings/method_get.go @@ -0,0 +1,55 @@ +package tenantsettings + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TenantSettingsContract +} + +// Get ... +func (c TenantSettingsClient) Get(ctx context.Context, id ServiceId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/settings/public", 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 TenantSettingsContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantsettings/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/tenantsettings/method_listbyservice.go new file mode 100644 index 00000000000..12487f36224 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantsettings/method_listbyservice.go @@ -0,0 +1,133 @@ +package tenantsettings + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TenantSettingsContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []TenantSettingsContract +} + +type ListByServiceOperationOptions struct { + Filter *string +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c TenantSettingsClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/settings", 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 *[]TenantSettingsContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c TenantSettingsClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, TenantSettingsContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TenantSettingsClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate TenantSettingsContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]TenantSettingsContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantsettings/model_tenantsettingscontract.go b/resource-manager/apimanagement/2024-05-01/tenantsettings/model_tenantsettingscontract.go new file mode 100644 index 00000000000..b504942475f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantsettings/model_tenantsettingscontract.go @@ -0,0 +1,11 @@ +package tenantsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TenantSettingsContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *TenantSettingsContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantsettings/model_tenantsettingscontractproperties.go b/resource-manager/apimanagement/2024-05-01/tenantsettings/model_tenantsettingscontractproperties.go new file mode 100644 index 00000000000..7e4929b92bb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantsettings/model_tenantsettingscontractproperties.go @@ -0,0 +1,8 @@ +package tenantsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TenantSettingsContractProperties struct { + Settings *map[string]string `json:"settings,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/tenantsettings/predicates.go b/resource-manager/apimanagement/2024-05-01/tenantsettings/predicates.go new file mode 100644 index 00000000000..6cba8bfd733 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantsettings/predicates.go @@ -0,0 +1,27 @@ +package tenantsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TenantSettingsContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p TenantSettingsContractOperationPredicate) Matches(input TenantSettingsContract) 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/apimanagement/2024-05-01/tenantsettings/version.go b/resource-manager/apimanagement/2024-05-01/tenantsettings/version.go new file mode 100644 index 00000000000..bc85128acd5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/tenantsettings/version.go @@ -0,0 +1,12 @@ +package tenantsettings + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/tenantsettings/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/user/README.md b/resource-manager/apimanagement/2024-05-01/user/README.md new file mode 100644 index 00000000000..d3832250562 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/user/README.md @@ -0,0 +1,123 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/user` Documentation + +The `user` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/user" +``` + + +### Client Initialization + +```go +client := user.NewUserClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `UserClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := user.NewUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue") + +payload := user.UserCreateParameters{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, user.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `UserClient.Delete` + +```go +ctx := context.TODO() +id := user.NewUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue") + +if err := client.DeleteThenPoll(ctx, id, user.DefaultDeleteOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `UserClient.Get` + +```go +ctx := context.TODO() +id := user.NewUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue") + +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: `UserClient.GetEntityTag` + +```go +ctx := context.TODO() +id := user.NewUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `UserClient.ListByService` + +```go +ctx := context.TODO() +id := user.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, user.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, user.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `UserClient.Update` + +```go +ctx := context.TODO() +id := user.NewUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue") + +payload := user.UserUpdateParameters{ + // ... +} + + +read, err := client.Update(ctx, id, payload, user.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/user/client.go b/resource-manager/apimanagement/2024-05-01/user/client.go new file mode 100644 index 00000000000..3d1a0eb8bf3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/user/client.go @@ -0,0 +1,26 @@ +package user + +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 UserClient struct { + Client *resourcemanager.Client +} + +func NewUserClientWithBaseURI(sdkApi sdkEnv.Api) (*UserClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "user", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating UserClient: %+v", err) + } + + return &UserClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/user/constants.go b/resource-manager/apimanagement/2024-05-01/user/constants.go new file mode 100644 index 00000000000..83573cf87af --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/user/constants.go @@ -0,0 +1,183 @@ +package user + +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 AppType string + +const ( + AppTypeDeveloperPortal AppType = "developerPortal" + AppTypePortal AppType = "portal" +) + +func PossibleValuesForAppType() []string { + return []string{ + string(AppTypeDeveloperPortal), + string(AppTypePortal), + } +} + +func (s *AppType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAppType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAppType(input string) (*AppType, error) { + vals := map[string]AppType{ + "developerportal": AppTypeDeveloperPortal, + "portal": AppTypePortal, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AppType(input) + return &out, nil +} + +type Confirmation string + +const ( + ConfirmationInvite Confirmation = "invite" + ConfirmationSignup Confirmation = "signup" +) + +func PossibleValuesForConfirmation() []string { + return []string{ + string(ConfirmationInvite), + string(ConfirmationSignup), + } +} + +func (s *Confirmation) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfirmation(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseConfirmation(input string) (*Confirmation, error) { + vals := map[string]Confirmation{ + "invite": ConfirmationInvite, + "signup": ConfirmationSignup, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Confirmation(input) + return &out, nil +} + +type GroupType string + +const ( + GroupTypeCustom GroupType = "custom" + GroupTypeExternal GroupType = "external" + GroupTypeSystem GroupType = "system" +) + +func PossibleValuesForGroupType() []string { + return []string{ + string(GroupTypeCustom), + string(GroupTypeExternal), + string(GroupTypeSystem), + } +} + +func (s *GroupType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGroupType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseGroupType(input string) (*GroupType, error) { + vals := map[string]GroupType{ + "custom": GroupTypeCustom, + "external": GroupTypeExternal, + "system": GroupTypeSystem, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := GroupType(input) + return &out, nil +} + +type UserState string + +const ( + UserStateActive UserState = "active" + UserStateBlocked UserState = "blocked" + UserStateDeleted UserState = "deleted" + UserStatePending UserState = "pending" +) + +func PossibleValuesForUserState() []string { + return []string{ + string(UserStateActive), + string(UserStateBlocked), + string(UserStateDeleted), + string(UserStatePending), + } +} + +func (s *UserState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUserState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseUserState(input string) (*UserState, error) { + vals := map[string]UserState{ + "active": UserStateActive, + "blocked": UserStateBlocked, + "deleted": UserStateDeleted, + "pending": UserStatePending, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UserState(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/user/id_service.go b/resource-manager/apimanagement/2024-05-01/user/id_service.go new file mode 100644 index 00000000000..4793d7dba1c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/user/id_service.go @@ -0,0 +1,130 @@ +package user + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/user/id_service_test.go b/resource-manager/apimanagement/2024-05-01/user/id_service_test.go new file mode 100644 index 00000000000..af608daf21b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/user/id_service_test.go @@ -0,0 +1,282 @@ +package user + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/user/id_user.go b/resource-manager/apimanagement/2024-05-01/user/id_user.go new file mode 100644 index 00000000000..46e79677949 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/user/id_user.go @@ -0,0 +1,139 @@ +package user + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&UserId{}) +} + +var _ resourceids.ResourceId = &UserId{} + +// UserId is a struct representing the Resource ID for a User +type UserId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + UserId string +} + +// NewUserID returns a new UserId struct +func NewUserID(subscriptionId string, resourceGroupName string, serviceName string, userId string) UserId { + return UserId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + UserId: userId, + } +} + +// ParseUserID parses 'input' into a UserId +func ParseUserID(input string) (*UserId, error) { + parser := resourceids.NewParserFromResourceIdType(&UserId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UserId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseUserIDInsensitively parses 'input' case-insensitively into a UserId +// note: this method should only be used for API response data and not user input +func ParseUserIDInsensitively(input string) (*UserId, error) { + parser := resourceids.NewParserFromResourceIdType(&UserId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UserId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *UserId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.UserId, ok = input.Parsed["userId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "userId", input) + } + + return nil +} + +// ValidateUserID checks that 'input' can be parsed as a User ID +func ValidateUserID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseUserID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted User ID +func (id UserId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/users/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.UserId) +} + +// Segments returns a slice of Resource ID Segments which comprise this User ID +func (id UserId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticUsers", "users", "users"), + resourceids.UserSpecifiedSegment("userId", "userIdValue"), + } +} + +// String returns a human-readable description of this User ID +func (id UserId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("User: %q", id.UserId), + } + return fmt.Sprintf("User (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/user/id_user_test.go b/resource-manager/apimanagement/2024-05-01/user/id_user_test.go new file mode 100644 index 00000000000..8a74c29d481 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/user/id_user_test.go @@ -0,0 +1,327 @@ +package user + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &UserId{} + +func TestNewUserID(t *testing.T) { + id := NewUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.UserId != "userIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'UserId'", id.UserId, "userIdValue") + } +} + +func TestFormatUserID(t *testing.T) { + actual := NewUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseUserID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UserId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue", + Expected: &UserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + UserId: "userIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUserID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.UserId != v.Expected.UserId { + t.Fatalf("Expected %q but got %q for UserId", v.Expected.UserId, actual.UserId) + } + + } +} + +func TestParseUserIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UserId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue", + Expected: &UserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + UserId: "userIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs/uSeRiDvAlUe", + Expected: &UserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + UserId: "uSeRiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs/uSeRiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUserIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.UserId != v.Expected.UserId { + t.Fatalf("Expected %q but got %q for UserId", v.Expected.UserId, actual.UserId) + } + + } +} + +func TestSegmentsForUserId(t *testing.T) { + segments := UserId{}.Segments() + if len(segments) == 0 { + t.Fatalf("UserId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/user/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/user/method_createorupdate.go new file mode 100644 index 00000000000..b1cf998602d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/user/method_createorupdate.go @@ -0,0 +1,91 @@ +package user + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *UserContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string + Notify *bool +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Notify != nil { + out.Append("notify", fmt.Sprintf("%v", *o.Notify)) + } + return &out +} + +// CreateOrUpdate ... +func (c UserClient) CreateOrUpdate(ctx context.Context, id UserId, input UserCreateParameters, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 UserContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/user/method_delete.go b/resource-manager/apimanagement/2024-05-01/user/method_delete.go new file mode 100644 index 00000000000..e5d13dba442 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/user/method_delete.go @@ -0,0 +1,109 @@ +package user + +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 +} + +type DeleteOperationOptions struct { + AppType *AppType + DeleteSubscriptions *bool + IfMatch *string + Notify *bool +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.AppType != nil { + out.Append("appType", fmt.Sprintf("%v", *o.AppType)) + } + if o.DeleteSubscriptions != nil { + out.Append("deleteSubscriptions", fmt.Sprintf("%v", *o.DeleteSubscriptions)) + } + if o.Notify != nil { + out.Append("notify", fmt.Sprintf("%v", *o.Notify)) + } + return &out +} + +// Delete ... +func (c UserClient) Delete(ctx context.Context, id UserId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + 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 UserClient) DeleteThenPoll(ctx context.Context, id UserId, options DeleteOperationOptions) error { + result, err := c.Delete(ctx, id, options) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/apimanagement/2024-05-01/user/method_get.go b/resource-manager/apimanagement/2024-05-01/user/method_get.go new file mode 100644 index 00000000000..1237761289c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/user/method_get.go @@ -0,0 +1,54 @@ +package user + +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 *UserContract +} + +// Get ... +func (c UserClient) Get(ctx context.Context, id UserId) (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 UserContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/user/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/user/method_getentitytag.go new file mode 100644 index 00000000000..bc31a7c3697 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/user/method_getentitytag.go @@ -0,0 +1,46 @@ +package user + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c UserClient) GetEntityTag(ctx context.Context, id UserId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/user/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/user/method_listbyservice.go new file mode 100644 index 00000000000..e098057b246 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/user/method_listbyservice.go @@ -0,0 +1,145 @@ +package user + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]UserContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []UserContract +} + +type ListByServiceOperationOptions struct { + ExpandGroups *bool + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.ExpandGroups != nil { + out.Append("expandGroups", fmt.Sprintf("%v", *o.ExpandGroups)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c UserClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/users", 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 *[]UserContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c UserClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, UserContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c UserClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate UserContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]UserContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/user/method_update.go b/resource-manager/apimanagement/2024-05-01/user/method_update.go new file mode 100644 index 00000000000..11353f91240 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/user/method_update.go @@ -0,0 +1,87 @@ +package user + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *UserContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c UserClient) Update(ctx context.Context, id UserId, input UserUpdateParameters, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 UserContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/user/model_groupcontractproperties.go b/resource-manager/apimanagement/2024-05-01/user/model_groupcontractproperties.go new file mode 100644 index 00000000000..1c489664e48 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/user/model_groupcontractproperties.go @@ -0,0 +1,12 @@ +package user + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupContractProperties struct { + BuiltIn *bool `json:"builtIn,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName string `json:"displayName"` + ExternalId *string `json:"externalId,omitempty"` + Type *GroupType `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/user/model_usercontract.go b/resource-manager/apimanagement/2024-05-01/user/model_usercontract.go new file mode 100644 index 00000000000..024c5b40beb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/user/model_usercontract.go @@ -0,0 +1,11 @@ +package user + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *UserContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/user/model_usercontractproperties.go b/resource-manager/apimanagement/2024-05-01/user/model_usercontractproperties.go new file mode 100644 index 00000000000..b70e93a62f3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/user/model_usercontractproperties.go @@ -0,0 +1,33 @@ +package user + +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 UserContractProperties struct { + Email *string `json:"email,omitempty"` + FirstName *string `json:"firstName,omitempty"` + Groups *[]GroupContractProperties `json:"groups,omitempty"` + Identities *[]UserIdentityContract `json:"identities,omitempty"` + LastName *string `json:"lastName,omitempty"` + Note *string `json:"note,omitempty"` + RegistrationDate *string `json:"registrationDate,omitempty"` + State *UserState `json:"state,omitempty"` +} + +func (o *UserContractProperties) GetRegistrationDateAsTime() (*time.Time, error) { + if o.RegistrationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RegistrationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *UserContractProperties) SetRegistrationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RegistrationDate = &formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/user/model_usercreateparameterproperties.go b/resource-manager/apimanagement/2024-05-01/user/model_usercreateparameterproperties.go new file mode 100644 index 00000000000..8a9747c07be --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/user/model_usercreateparameterproperties.go @@ -0,0 +1,16 @@ +package user + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserCreateParameterProperties struct { + AppType *AppType `json:"appType,omitempty"` + Confirmation *Confirmation `json:"confirmation,omitempty"` + Email string `json:"email"` + FirstName string `json:"firstName"` + Identities *[]UserIdentityContract `json:"identities,omitempty"` + LastName string `json:"lastName"` + Note *string `json:"note,omitempty"` + Password *string `json:"password,omitempty"` + State *UserState `json:"state,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/user/model_usercreateparameters.go b/resource-manager/apimanagement/2024-05-01/user/model_usercreateparameters.go new file mode 100644 index 00000000000..06d702b0df7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/user/model_usercreateparameters.go @@ -0,0 +1,8 @@ +package user + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserCreateParameters struct { + Properties *UserCreateParameterProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/user/model_useridentitycontract.go b/resource-manager/apimanagement/2024-05-01/user/model_useridentitycontract.go new file mode 100644 index 00000000000..c4b4b956d02 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/user/model_useridentitycontract.go @@ -0,0 +1,9 @@ +package user + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserIdentityContract struct { + Id *string `json:"id,omitempty"` + Provider *string `json:"provider,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/user/model_userupdateparameters.go b/resource-manager/apimanagement/2024-05-01/user/model_userupdateparameters.go new file mode 100644 index 00000000000..7ba5b6cdc3e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/user/model_userupdateparameters.go @@ -0,0 +1,8 @@ +package user + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserUpdateParameters struct { + Properties *UserUpdateParametersProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/user/model_userupdateparametersproperties.go b/resource-manager/apimanagement/2024-05-01/user/model_userupdateparametersproperties.go new file mode 100644 index 00000000000..32cbae72c30 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/user/model_userupdateparametersproperties.go @@ -0,0 +1,14 @@ +package user + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserUpdateParametersProperties struct { + Email *string `json:"email,omitempty"` + FirstName *string `json:"firstName,omitempty"` + Identities *[]UserIdentityContract `json:"identities,omitempty"` + LastName *string `json:"lastName,omitempty"` + Note *string `json:"note,omitempty"` + Password *string `json:"password,omitempty"` + State *UserState `json:"state,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/user/predicates.go b/resource-manager/apimanagement/2024-05-01/user/predicates.go new file mode 100644 index 00000000000..70f897ed2a9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/user/predicates.go @@ -0,0 +1,27 @@ +package user + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p UserContractOperationPredicate) Matches(input UserContract) 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/apimanagement/2024-05-01/user/version.go b/resource-manager/apimanagement/2024-05-01/user/version.go new file mode 100644 index 00000000000..15e97eb1be0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/user/version.go @@ -0,0 +1,12 @@ +package user + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/user/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/userconfirmationpasswordsend/client.go b/resource-manager/apimanagement/2024-05-01/userconfirmationpasswordsend/client.go new file mode 100644 index 00000000000..2be6b996059 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/userconfirmationpasswordsend/client.go @@ -0,0 +1,26 @@ +package userconfirmationpasswordsend + +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 UserConfirmationPasswordSendClient struct { + Client *resourcemanager.Client +} + +func NewUserConfirmationPasswordSendClientWithBaseURI(sdkApi sdkEnv.Api) (*UserConfirmationPasswordSendClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "userconfirmationpasswordsend", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating UserConfirmationPasswordSendClient: %+v", err) + } + + return &UserConfirmationPasswordSendClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/userconfirmationpasswordsend/constants.go b/resource-manager/apimanagement/2024-05-01/userconfirmationpasswordsend/constants.go new file mode 100644 index 00000000000..c532eea3196 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/userconfirmationpasswordsend/constants.go @@ -0,0 +1,51 @@ +package userconfirmationpasswordsend + +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 AppType string + +const ( + AppTypeDeveloperPortal AppType = "developerPortal" + AppTypePortal AppType = "portal" +) + +func PossibleValuesForAppType() []string { + return []string{ + string(AppTypeDeveloperPortal), + string(AppTypePortal), + } +} + +func (s *AppType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAppType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAppType(input string) (*AppType, error) { + vals := map[string]AppType{ + "developerportal": AppTypeDeveloperPortal, + "portal": AppTypePortal, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AppType(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/userconfirmationpasswordsend/id_user.go b/resource-manager/apimanagement/2024-05-01/userconfirmationpasswordsend/id_user.go new file mode 100644 index 00000000000..119b0594c8a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/userconfirmationpasswordsend/id_user.go @@ -0,0 +1,139 @@ +package userconfirmationpasswordsend + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&UserId{}) +} + +var _ resourceids.ResourceId = &UserId{} + +// UserId is a struct representing the Resource ID for a User +type UserId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + UserId string +} + +// NewUserID returns a new UserId struct +func NewUserID(subscriptionId string, resourceGroupName string, serviceName string, userId string) UserId { + return UserId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + UserId: userId, + } +} + +// ParseUserID parses 'input' into a UserId +func ParseUserID(input string) (*UserId, error) { + parser := resourceids.NewParserFromResourceIdType(&UserId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UserId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseUserIDInsensitively parses 'input' case-insensitively into a UserId +// note: this method should only be used for API response data and not user input +func ParseUserIDInsensitively(input string) (*UserId, error) { + parser := resourceids.NewParserFromResourceIdType(&UserId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UserId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *UserId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.UserId, ok = input.Parsed["userId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "userId", input) + } + + return nil +} + +// ValidateUserID checks that 'input' can be parsed as a User ID +func ValidateUserID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseUserID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted User ID +func (id UserId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/users/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.UserId) +} + +// Segments returns a slice of Resource ID Segments which comprise this User ID +func (id UserId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticUsers", "users", "users"), + resourceids.UserSpecifiedSegment("userId", "userIdValue"), + } +} + +// String returns a human-readable description of this User ID +func (id UserId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("User: %q", id.UserId), + } + return fmt.Sprintf("User (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/userconfirmationpasswordsend/id_user_test.go b/resource-manager/apimanagement/2024-05-01/userconfirmationpasswordsend/id_user_test.go new file mode 100644 index 00000000000..4873f4a0dfb --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/userconfirmationpasswordsend/id_user_test.go @@ -0,0 +1,327 @@ +package userconfirmationpasswordsend + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &UserId{} + +func TestNewUserID(t *testing.T) { + id := NewUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.UserId != "userIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'UserId'", id.UserId, "userIdValue") + } +} + +func TestFormatUserID(t *testing.T) { + actual := NewUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseUserID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UserId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue", + Expected: &UserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + UserId: "userIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUserID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.UserId != v.Expected.UserId { + t.Fatalf("Expected %q but got %q for UserId", v.Expected.UserId, actual.UserId) + } + + } +} + +func TestParseUserIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UserId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue", + Expected: &UserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + UserId: "userIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs/uSeRiDvAlUe", + Expected: &UserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + UserId: "uSeRiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs/uSeRiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUserIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.UserId != v.Expected.UserId { + t.Fatalf("Expected %q but got %q for UserId", v.Expected.UserId, actual.UserId) + } + + } +} + +func TestSegmentsForUserId(t *testing.T) { + segments := UserId{}.Segments() + if len(segments) == 0 { + t.Fatalf("UserId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/userconfirmationpasswordsend/method_userconfirmationpasswordsend.go b/resource-manager/apimanagement/2024-05-01/userconfirmationpasswordsend/method_userconfirmationpasswordsend.go new file mode 100644 index 00000000000..b1915a44d82 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/userconfirmationpasswordsend/method_userconfirmationpasswordsend.go @@ -0,0 +1,75 @@ +package userconfirmationpasswordsend + +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 UserConfirmationPasswordSendOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type UserConfirmationPasswordSendOperationOptions struct { + AppType *AppType +} + +func DefaultUserConfirmationPasswordSendOperationOptions() UserConfirmationPasswordSendOperationOptions { + return UserConfirmationPasswordSendOperationOptions{} +} + +func (o UserConfirmationPasswordSendOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o UserConfirmationPasswordSendOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UserConfirmationPasswordSendOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.AppType != nil { + out.Append("appType", fmt.Sprintf("%v", *o.AppType)) + } + return &out +} + +// UserConfirmationPasswordSend ... +func (c UserConfirmationPasswordSendClient) UserConfirmationPasswordSend(ctx context.Context, id UserId, options UserConfirmationPasswordSendOperationOptions) (result UserConfirmationPasswordSendOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + OptionsObject: options, + Path: fmt.Sprintf("%s/confirmations/password/send", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/userconfirmationpasswordsend/version.go b/resource-manager/apimanagement/2024-05-01/userconfirmationpasswordsend/version.go new file mode 100644 index 00000000000..2314ee0c304 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/userconfirmationpasswordsend/version.go @@ -0,0 +1,12 @@ +package userconfirmationpasswordsend + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/userconfirmationpasswordsend/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/usergroup/README.md b/resource-manager/apimanagement/2024-05-01/usergroup/README.md new file mode 100644 index 00000000000..41ed655939a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usergroup/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/usergroup` Documentation + +The `usergroup` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/usergroup" +``` + + +### Client Initialization + +```go +client := usergroup.NewUserGroupClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `UserGroupClient.List` + +```go +ctx := context.TODO() +id := usergroup.NewUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue") + +// alternatively `client.List(ctx, id, usergroup.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, usergroup.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/usergroup/client.go b/resource-manager/apimanagement/2024-05-01/usergroup/client.go new file mode 100644 index 00000000000..74829119980 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usergroup/client.go @@ -0,0 +1,26 @@ +package usergroup + +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 UserGroupClient struct { + Client *resourcemanager.Client +} + +func NewUserGroupClientWithBaseURI(sdkApi sdkEnv.Api) (*UserGroupClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "usergroup", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating UserGroupClient: %+v", err) + } + + return &UserGroupClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/usergroup/constants.go b/resource-manager/apimanagement/2024-05-01/usergroup/constants.go new file mode 100644 index 00000000000..8762d75fc71 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usergroup/constants.go @@ -0,0 +1,54 @@ +package usergroup + +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 GroupType string + +const ( + GroupTypeCustom GroupType = "custom" + GroupTypeExternal GroupType = "external" + GroupTypeSystem GroupType = "system" +) + +func PossibleValuesForGroupType() []string { + return []string{ + string(GroupTypeCustom), + string(GroupTypeExternal), + string(GroupTypeSystem), + } +} + +func (s *GroupType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGroupType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseGroupType(input string) (*GroupType, error) { + vals := map[string]GroupType{ + "custom": GroupTypeCustom, + "external": GroupTypeExternal, + "system": GroupTypeSystem, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := GroupType(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/usergroup/id_user.go b/resource-manager/apimanagement/2024-05-01/usergroup/id_user.go new file mode 100644 index 00000000000..dbcd62c7aff --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usergroup/id_user.go @@ -0,0 +1,139 @@ +package usergroup + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&UserId{}) +} + +var _ resourceids.ResourceId = &UserId{} + +// UserId is a struct representing the Resource ID for a User +type UserId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + UserId string +} + +// NewUserID returns a new UserId struct +func NewUserID(subscriptionId string, resourceGroupName string, serviceName string, userId string) UserId { + return UserId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + UserId: userId, + } +} + +// ParseUserID parses 'input' into a UserId +func ParseUserID(input string) (*UserId, error) { + parser := resourceids.NewParserFromResourceIdType(&UserId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UserId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseUserIDInsensitively parses 'input' case-insensitively into a UserId +// note: this method should only be used for API response data and not user input +func ParseUserIDInsensitively(input string) (*UserId, error) { + parser := resourceids.NewParserFromResourceIdType(&UserId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UserId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *UserId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.UserId, ok = input.Parsed["userId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "userId", input) + } + + return nil +} + +// ValidateUserID checks that 'input' can be parsed as a User ID +func ValidateUserID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseUserID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted User ID +func (id UserId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/users/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.UserId) +} + +// Segments returns a slice of Resource ID Segments which comprise this User ID +func (id UserId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticUsers", "users", "users"), + resourceids.UserSpecifiedSegment("userId", "userIdValue"), + } +} + +// String returns a human-readable description of this User ID +func (id UserId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("User: %q", id.UserId), + } + return fmt.Sprintf("User (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/usergroup/id_user_test.go b/resource-manager/apimanagement/2024-05-01/usergroup/id_user_test.go new file mode 100644 index 00000000000..0b6e351dae1 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usergroup/id_user_test.go @@ -0,0 +1,327 @@ +package usergroup + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &UserId{} + +func TestNewUserID(t *testing.T) { + id := NewUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.UserId != "userIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'UserId'", id.UserId, "userIdValue") + } +} + +func TestFormatUserID(t *testing.T) { + actual := NewUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseUserID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UserId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue", + Expected: &UserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + UserId: "userIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUserID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.UserId != v.Expected.UserId { + t.Fatalf("Expected %q but got %q for UserId", v.Expected.UserId, actual.UserId) + } + + } +} + +func TestParseUserIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UserId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue", + Expected: &UserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + UserId: "userIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs/uSeRiDvAlUe", + Expected: &UserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + UserId: "uSeRiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs/uSeRiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUserIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.UserId != v.Expected.UserId { + t.Fatalf("Expected %q but got %q for UserId", v.Expected.UserId, actual.UserId) + } + + } +} + +func TestSegmentsForUserId(t *testing.T) { + segments := UserId{}.Segments() + if len(segments) == 0 { + t.Fatalf("UserId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/usergroup/method_list.go b/resource-manager/apimanagement/2024-05-01/usergroup/method_list.go new file mode 100644 index 00000000000..cfe2c191701 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usergroup/method_list.go @@ -0,0 +1,141 @@ +package usergroup + +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 *[]GroupContract +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []GroupContract +} + +type ListOperationOptions struct { + Filter *string + Skip *int64 + 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.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c UserGroupClient) List(ctx context.Context, id UserId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/groups", 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 *[]GroupContract `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 UserGroupClient) ListComplete(ctx context.Context, id UserId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, GroupContractOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c UserGroupClient) ListCompleteMatchingPredicate(ctx context.Context, id UserId, options ListOperationOptions, predicate GroupContractOperationPredicate) (result ListCompleteResult, err error) { + items := make([]GroupContract, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/usergroup/model_groupcontract.go b/resource-manager/apimanagement/2024-05-01/usergroup/model_groupcontract.go new file mode 100644 index 00000000000..4bf46422019 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usergroup/model_groupcontract.go @@ -0,0 +1,11 @@ +package usergroup + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *GroupContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/usergroup/model_groupcontractproperties.go b/resource-manager/apimanagement/2024-05-01/usergroup/model_groupcontractproperties.go new file mode 100644 index 00000000000..5d66970ff75 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usergroup/model_groupcontractproperties.go @@ -0,0 +1,12 @@ +package usergroup + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupContractProperties struct { + BuiltIn *bool `json:"builtIn,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName string `json:"displayName"` + ExternalId *string `json:"externalId,omitempty"` + Type *GroupType `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/usergroup/predicates.go b/resource-manager/apimanagement/2024-05-01/usergroup/predicates.go new file mode 100644 index 00000000000..b8c0bb39d17 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usergroup/predicates.go @@ -0,0 +1,27 @@ +package usergroup + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p GroupContractOperationPredicate) Matches(input GroupContract) 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/apimanagement/2024-05-01/usergroup/version.go b/resource-manager/apimanagement/2024-05-01/usergroup/version.go new file mode 100644 index 00000000000..599537e4ef9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usergroup/version.go @@ -0,0 +1,12 @@ +package usergroup + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/usergroup/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/useridentity/README.md b/resource-manager/apimanagement/2024-05-01/useridentity/README.md new file mode 100644 index 00000000000..c81f8caeff6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/useridentity/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/useridentity` Documentation + +The `useridentity` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/useridentity" +``` + + +### Client Initialization + +```go +client := useridentity.NewUserIdentityClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `UserIdentityClient.UserIdentitiesList` + +```go +ctx := context.TODO() +id := useridentity.NewUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue") + +// alternatively `client.UserIdentitiesList(ctx, id)` can be used to do batched pagination +items, err := client.UserIdentitiesListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/useridentity/client.go b/resource-manager/apimanagement/2024-05-01/useridentity/client.go new file mode 100644 index 00000000000..ba997999551 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/useridentity/client.go @@ -0,0 +1,26 @@ +package useridentity + +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 UserIdentityClient struct { + Client *resourcemanager.Client +} + +func NewUserIdentityClientWithBaseURI(sdkApi sdkEnv.Api) (*UserIdentityClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "useridentity", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating UserIdentityClient: %+v", err) + } + + return &UserIdentityClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/useridentity/id_user.go b/resource-manager/apimanagement/2024-05-01/useridentity/id_user.go new file mode 100644 index 00000000000..81e0f7f5380 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/useridentity/id_user.go @@ -0,0 +1,139 @@ +package useridentity + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&UserId{}) +} + +var _ resourceids.ResourceId = &UserId{} + +// UserId is a struct representing the Resource ID for a User +type UserId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + UserId string +} + +// NewUserID returns a new UserId struct +func NewUserID(subscriptionId string, resourceGroupName string, serviceName string, userId string) UserId { + return UserId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + UserId: userId, + } +} + +// ParseUserID parses 'input' into a UserId +func ParseUserID(input string) (*UserId, error) { + parser := resourceids.NewParserFromResourceIdType(&UserId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UserId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseUserIDInsensitively parses 'input' case-insensitively into a UserId +// note: this method should only be used for API response data and not user input +func ParseUserIDInsensitively(input string) (*UserId, error) { + parser := resourceids.NewParserFromResourceIdType(&UserId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UserId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *UserId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.UserId, ok = input.Parsed["userId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "userId", input) + } + + return nil +} + +// ValidateUserID checks that 'input' can be parsed as a User ID +func ValidateUserID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseUserID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted User ID +func (id UserId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/users/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.UserId) +} + +// Segments returns a slice of Resource ID Segments which comprise this User ID +func (id UserId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticUsers", "users", "users"), + resourceids.UserSpecifiedSegment("userId", "userIdValue"), + } +} + +// String returns a human-readable description of this User ID +func (id UserId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("User: %q", id.UserId), + } + return fmt.Sprintf("User (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/useridentity/id_user_test.go b/resource-manager/apimanagement/2024-05-01/useridentity/id_user_test.go new file mode 100644 index 00000000000..77901d3a604 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/useridentity/id_user_test.go @@ -0,0 +1,327 @@ +package useridentity + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &UserId{} + +func TestNewUserID(t *testing.T) { + id := NewUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.UserId != "userIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'UserId'", id.UserId, "userIdValue") + } +} + +func TestFormatUserID(t *testing.T) { + actual := NewUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseUserID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UserId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue", + Expected: &UserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + UserId: "userIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUserID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.UserId != v.Expected.UserId { + t.Fatalf("Expected %q but got %q for UserId", v.Expected.UserId, actual.UserId) + } + + } +} + +func TestParseUserIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UserId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue", + Expected: &UserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + UserId: "userIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs/uSeRiDvAlUe", + Expected: &UserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + UserId: "uSeRiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs/uSeRiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUserIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.UserId != v.Expected.UserId { + t.Fatalf("Expected %q but got %q for UserId", v.Expected.UserId, actual.UserId) + } + + } +} + +func TestSegmentsForUserId(t *testing.T) { + segments := UserId{}.Segments() + if len(segments) == 0 { + t.Fatalf("UserId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/useridentity/method_useridentitieslist.go b/resource-manager/apimanagement/2024-05-01/useridentity/method_useridentitieslist.go new file mode 100644 index 00000000000..43e22220140 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/useridentity/method_useridentitieslist.go @@ -0,0 +1,105 @@ +package useridentity + +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 UserIdentitiesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]UserIdentityContract +} + +type UserIdentitiesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []UserIdentityContract +} + +type UserIdentitiesListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *UserIdentitiesListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// UserIdentitiesList ... +func (c UserIdentityClient) UserIdentitiesList(ctx context.Context, id UserId) (result UserIdentitiesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &UserIdentitiesListCustomPager{}, + Path: fmt.Sprintf("%s/identities", 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 *[]UserIdentityContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// UserIdentitiesListComplete retrieves all the results into a single object +func (c UserIdentityClient) UserIdentitiesListComplete(ctx context.Context, id UserId) (UserIdentitiesListCompleteResult, error) { + return c.UserIdentitiesListCompleteMatchingPredicate(ctx, id, UserIdentityContractOperationPredicate{}) +} + +// UserIdentitiesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c UserIdentityClient) UserIdentitiesListCompleteMatchingPredicate(ctx context.Context, id UserId, predicate UserIdentityContractOperationPredicate) (result UserIdentitiesListCompleteResult, err error) { + items := make([]UserIdentityContract, 0) + + resp, err := c.UserIdentitiesList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = UserIdentitiesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/useridentity/model_useridentitycontract.go b/resource-manager/apimanagement/2024-05-01/useridentity/model_useridentitycontract.go new file mode 100644 index 00000000000..b2f24c6184b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/useridentity/model_useridentitycontract.go @@ -0,0 +1,9 @@ +package useridentity + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserIdentityContract struct { + Id *string `json:"id,omitempty"` + Provider *string `json:"provider,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/useridentity/predicates.go b/resource-manager/apimanagement/2024-05-01/useridentity/predicates.go new file mode 100644 index 00000000000..a706d5676ec --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/useridentity/predicates.go @@ -0,0 +1,22 @@ +package useridentity + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserIdentityContractOperationPredicate struct { + Id *string + Provider *string +} + +func (p UserIdentityContractOperationPredicate) Matches(input UserIdentityContract) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Provider != nil && (input.Provider == nil || *p.Provider != *input.Provider) { + return false + } + + return true +} diff --git a/resource-manager/apimanagement/2024-05-01/useridentity/version.go b/resource-manager/apimanagement/2024-05-01/useridentity/version.go new file mode 100644 index 00000000000..5ef00f1e24f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/useridentity/version.go @@ -0,0 +1,12 @@ +package useridentity + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/useridentity/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/users/README.md b/resource-manager/apimanagement/2024-05-01/users/README.md new file mode 100644 index 00000000000..23b4be2f0c7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/users/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/users` Documentation + +The `users` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/users" +``` + + +### Client Initialization + +```go +client := users.NewUsersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `UsersClient.UserGenerateSsoUrl` + +```go +ctx := context.TODO() +id := users.NewUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue") + +read, err := client.UserGenerateSsoUrl(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/apimanagement/2024-05-01/users/client.go b/resource-manager/apimanagement/2024-05-01/users/client.go new file mode 100644 index 00000000000..61acff0d5ad --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/users/client.go @@ -0,0 +1,26 @@ +package users + +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 UsersClient struct { + Client *resourcemanager.Client +} + +func NewUsersClientWithBaseURI(sdkApi sdkEnv.Api) (*UsersClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "users", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating UsersClient: %+v", err) + } + + return &UsersClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/users/id_user.go b/resource-manager/apimanagement/2024-05-01/users/id_user.go new file mode 100644 index 00000000000..f309b6fbd68 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/users/id_user.go @@ -0,0 +1,139 @@ +package users + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&UserId{}) +} + +var _ resourceids.ResourceId = &UserId{} + +// UserId is a struct representing the Resource ID for a User +type UserId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + UserId string +} + +// NewUserID returns a new UserId struct +func NewUserID(subscriptionId string, resourceGroupName string, serviceName string, userId string) UserId { + return UserId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + UserId: userId, + } +} + +// ParseUserID parses 'input' into a UserId +func ParseUserID(input string) (*UserId, error) { + parser := resourceids.NewParserFromResourceIdType(&UserId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UserId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseUserIDInsensitively parses 'input' case-insensitively into a UserId +// note: this method should only be used for API response data and not user input +func ParseUserIDInsensitively(input string) (*UserId, error) { + parser := resourceids.NewParserFromResourceIdType(&UserId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UserId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *UserId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.UserId, ok = input.Parsed["userId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "userId", input) + } + + return nil +} + +// ValidateUserID checks that 'input' can be parsed as a User ID +func ValidateUserID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseUserID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted User ID +func (id UserId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/users/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.UserId) +} + +// Segments returns a slice of Resource ID Segments which comprise this User ID +func (id UserId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticUsers", "users", "users"), + resourceids.UserSpecifiedSegment("userId", "userIdValue"), + } +} + +// String returns a human-readable description of this User ID +func (id UserId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("User: %q", id.UserId), + } + return fmt.Sprintf("User (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/users/id_user_test.go b/resource-manager/apimanagement/2024-05-01/users/id_user_test.go new file mode 100644 index 00000000000..ddbb23a224f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/users/id_user_test.go @@ -0,0 +1,327 @@ +package users + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &UserId{} + +func TestNewUserID(t *testing.T) { + id := NewUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.UserId != "userIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'UserId'", id.UserId, "userIdValue") + } +} + +func TestFormatUserID(t *testing.T) { + actual := NewUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseUserID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UserId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue", + Expected: &UserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + UserId: "userIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUserID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.UserId != v.Expected.UserId { + t.Fatalf("Expected %q but got %q for UserId", v.Expected.UserId, actual.UserId) + } + + } +} + +func TestParseUserIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UserId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue", + Expected: &UserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + UserId: "userIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs/uSeRiDvAlUe", + Expected: &UserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + UserId: "uSeRiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs/uSeRiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUserIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.UserId != v.Expected.UserId { + t.Fatalf("Expected %q but got %q for UserId", v.Expected.UserId, actual.UserId) + } + + } +} + +func TestSegmentsForUserId(t *testing.T) { + segments := UserId{}.Segments() + if len(segments) == 0 { + t.Fatalf("UserId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/users/method_usergeneratessourl.go b/resource-manager/apimanagement/2024-05-01/users/method_usergeneratessourl.go new file mode 100644 index 00000000000..500ea8362b0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/users/method_usergeneratessourl.go @@ -0,0 +1,55 @@ +package users + +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 UserGenerateSsoUrlOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GenerateSsoUrlResult +} + +// UserGenerateSsoUrl ... +func (c UsersClient) UserGenerateSsoUrl(ctx context.Context, id UserId) (result UserGenerateSsoUrlOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/generateSsoUrl", 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 GenerateSsoUrlResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/users/model_generatessourlresult.go b/resource-manager/apimanagement/2024-05-01/users/model_generatessourlresult.go new file mode 100644 index 00000000000..f78768f2f31 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/users/model_generatessourlresult.go @@ -0,0 +1,8 @@ +package users + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenerateSsoUrlResult struct { + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/users/version.go b/resource-manager/apimanagement/2024-05-01/users/version.go new file mode 100644 index 00000000000..8e676626418 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/users/version.go @@ -0,0 +1,12 @@ +package users + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/users/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/usersubscription/README.md b/resource-manager/apimanagement/2024-05-01/usersubscription/README.md new file mode 100644 index 00000000000..9419f776291 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usersubscription/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/usersubscription` Documentation + +The `usersubscription` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/usersubscription" +``` + + +### Client Initialization + +```go +client := usersubscription.NewUserSubscriptionClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `UserSubscriptionClient.List` + +```go +ctx := context.TODO() +id := usersubscription.NewUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue") + +// alternatively `client.List(ctx, id, usersubscription.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, usersubscription.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/usersubscription/client.go b/resource-manager/apimanagement/2024-05-01/usersubscription/client.go new file mode 100644 index 00000000000..f9dd0627128 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usersubscription/client.go @@ -0,0 +1,26 @@ +package usersubscription + +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 UserSubscriptionClient struct { + Client *resourcemanager.Client +} + +func NewUserSubscriptionClientWithBaseURI(sdkApi sdkEnv.Api) (*UserSubscriptionClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "usersubscription", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating UserSubscriptionClient: %+v", err) + } + + return &UserSubscriptionClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/usersubscription/constants.go b/resource-manager/apimanagement/2024-05-01/usersubscription/constants.go new file mode 100644 index 00000000000..8999ff3cae7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usersubscription/constants.go @@ -0,0 +1,63 @@ +package usersubscription + +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 SubscriptionState string + +const ( + SubscriptionStateActive SubscriptionState = "active" + SubscriptionStateCancelled SubscriptionState = "cancelled" + SubscriptionStateExpired SubscriptionState = "expired" + SubscriptionStateRejected SubscriptionState = "rejected" + SubscriptionStateSubmitted SubscriptionState = "submitted" + SubscriptionStateSuspended SubscriptionState = "suspended" +) + +func PossibleValuesForSubscriptionState() []string { + return []string{ + string(SubscriptionStateActive), + string(SubscriptionStateCancelled), + string(SubscriptionStateExpired), + string(SubscriptionStateRejected), + string(SubscriptionStateSubmitted), + string(SubscriptionStateSuspended), + } +} + +func (s *SubscriptionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSubscriptionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSubscriptionState(input string) (*SubscriptionState, error) { + vals := map[string]SubscriptionState{ + "active": SubscriptionStateActive, + "cancelled": SubscriptionStateCancelled, + "expired": SubscriptionStateExpired, + "rejected": SubscriptionStateRejected, + "submitted": SubscriptionStateSubmitted, + "suspended": SubscriptionStateSuspended, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SubscriptionState(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/usersubscription/id_user.go b/resource-manager/apimanagement/2024-05-01/usersubscription/id_user.go new file mode 100644 index 00000000000..b993469b4bf --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usersubscription/id_user.go @@ -0,0 +1,139 @@ +package usersubscription + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&UserId{}) +} + +var _ resourceids.ResourceId = &UserId{} + +// UserId is a struct representing the Resource ID for a User +type UserId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + UserId string +} + +// NewUserID returns a new UserId struct +func NewUserID(subscriptionId string, resourceGroupName string, serviceName string, userId string) UserId { + return UserId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + UserId: userId, + } +} + +// ParseUserID parses 'input' into a UserId +func ParseUserID(input string) (*UserId, error) { + parser := resourceids.NewParserFromResourceIdType(&UserId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UserId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseUserIDInsensitively parses 'input' case-insensitively into a UserId +// note: this method should only be used for API response data and not user input +func ParseUserIDInsensitively(input string) (*UserId, error) { + parser := resourceids.NewParserFromResourceIdType(&UserId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UserId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *UserId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.UserId, ok = input.Parsed["userId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "userId", input) + } + + return nil +} + +// ValidateUserID checks that 'input' can be parsed as a User ID +func ValidateUserID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseUserID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted User ID +func (id UserId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/users/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.UserId) +} + +// Segments returns a slice of Resource ID Segments which comprise this User ID +func (id UserId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticUsers", "users", "users"), + resourceids.UserSpecifiedSegment("userId", "userIdValue"), + } +} + +// String returns a human-readable description of this User ID +func (id UserId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("User: %q", id.UserId), + } + return fmt.Sprintf("User (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/usersubscription/id_user_test.go b/resource-manager/apimanagement/2024-05-01/usersubscription/id_user_test.go new file mode 100644 index 00000000000..e83a0b59d1d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usersubscription/id_user_test.go @@ -0,0 +1,327 @@ +package usersubscription + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &UserId{} + +func TestNewUserID(t *testing.T) { + id := NewUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.UserId != "userIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'UserId'", id.UserId, "userIdValue") + } +} + +func TestFormatUserID(t *testing.T) { + actual := NewUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseUserID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UserId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue", + Expected: &UserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + UserId: "userIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUserID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.UserId != v.Expected.UserId { + t.Fatalf("Expected %q but got %q for UserId", v.Expected.UserId, actual.UserId) + } + + } +} + +func TestParseUserIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UserId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue", + Expected: &UserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + UserId: "userIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs/uSeRiDvAlUe", + Expected: &UserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + UserId: "uSeRiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs/uSeRiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUserIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.UserId != v.Expected.UserId { + t.Fatalf("Expected %q but got %q for UserId", v.Expected.UserId, actual.UserId) + } + + } +} + +func TestSegmentsForUserId(t *testing.T) { + segments := UserId{}.Segments() + if len(segments) == 0 { + t.Fatalf("UserId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/usersubscription/method_list.go b/resource-manager/apimanagement/2024-05-01/usersubscription/method_list.go new file mode 100644 index 00000000000..9acd966ed75 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usersubscription/method_list.go @@ -0,0 +1,141 @@ +package usersubscription + +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 *[]SubscriptionContract +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []SubscriptionContract +} + +type ListOperationOptions struct { + Filter *string + Skip *int64 + 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.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c UserSubscriptionClient) List(ctx context.Context, id UserId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/subscriptions", 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 *[]SubscriptionContract `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 UserSubscriptionClient) ListComplete(ctx context.Context, id UserId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, SubscriptionContractOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c UserSubscriptionClient) ListCompleteMatchingPredicate(ctx context.Context, id UserId, options ListOperationOptions, predicate SubscriptionContractOperationPredicate) (result ListCompleteResult, err error) { + items := make([]SubscriptionContract, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/usersubscription/model_subscriptioncontract.go b/resource-manager/apimanagement/2024-05-01/usersubscription/model_subscriptioncontract.go new file mode 100644 index 00000000000..d47524815a8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usersubscription/model_subscriptioncontract.go @@ -0,0 +1,11 @@ +package usersubscription + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SubscriptionContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/usersubscription/model_subscriptioncontractproperties.go b/resource-manager/apimanagement/2024-05-01/usersubscription/model_subscriptioncontractproperties.go new file mode 100644 index 00000000000..622694e53f3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usersubscription/model_subscriptioncontractproperties.go @@ -0,0 +1,86 @@ +package usersubscription + +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 SubscriptionContractProperties struct { + AllowTracing *bool `json:"allowTracing,omitempty"` + CreatedDate *string `json:"createdDate,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + EndDate *string `json:"endDate,omitempty"` + ExpirationDate *string `json:"expirationDate,omitempty"` + NotificationDate *string `json:"notificationDate,omitempty"` + OwnerId *string `json:"ownerId,omitempty"` + PrimaryKey *string `json:"primaryKey,omitempty"` + Scope string `json:"scope"` + SecondaryKey *string `json:"secondaryKey,omitempty"` + StartDate *string `json:"startDate,omitempty"` + State SubscriptionState `json:"state"` + StateComment *string `json:"stateComment,omitempty"` +} + +func (o *SubscriptionContractProperties) GetCreatedDateAsTime() (*time.Time, error) { + if o.CreatedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SubscriptionContractProperties) SetCreatedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedDate = &formatted +} + +func (o *SubscriptionContractProperties) GetEndDateAsTime() (*time.Time, error) { + if o.EndDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SubscriptionContractProperties) SetEndDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndDate = &formatted +} + +func (o *SubscriptionContractProperties) GetExpirationDateAsTime() (*time.Time, error) { + if o.ExpirationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpirationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SubscriptionContractProperties) SetExpirationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpirationDate = &formatted +} + +func (o *SubscriptionContractProperties) GetNotificationDateAsTime() (*time.Time, error) { + if o.NotificationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.NotificationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SubscriptionContractProperties) SetNotificationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.NotificationDate = &formatted +} + +func (o *SubscriptionContractProperties) GetStartDateAsTime() (*time.Time, error) { + if o.StartDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SubscriptionContractProperties) SetStartDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartDate = &formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/usersubscription/predicates.go b/resource-manager/apimanagement/2024-05-01/usersubscription/predicates.go new file mode 100644 index 00000000000..9b6a14afde7 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usersubscription/predicates.go @@ -0,0 +1,27 @@ +package usersubscription + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SubscriptionContractOperationPredicate) Matches(input SubscriptionContract) 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/apimanagement/2024-05-01/usersubscription/version.go b/resource-manager/apimanagement/2024-05-01/usersubscription/version.go new file mode 100644 index 00000000000..23a9c050f24 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usersubscription/version.go @@ -0,0 +1,12 @@ +package usersubscription + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/usersubscription/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/usertoken/README.md b/resource-manager/apimanagement/2024-05-01/usertoken/README.md new file mode 100644 index 00000000000..ff2551cb083 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usertoken/README.md @@ -0,0 +1,41 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/usertoken` Documentation + +The `usertoken` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/usertoken" +``` + + +### Client Initialization + +```go +client := usertoken.NewUserTokenClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `UserTokenClient.UserGetSharedAccessToken` + +```go +ctx := context.TODO() +id := usertoken.NewUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue") + +payload := usertoken.UserTokenParameters{ + // ... +} + + +read, err := client.UserGetSharedAccessToken(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/apimanagement/2024-05-01/usertoken/client.go b/resource-manager/apimanagement/2024-05-01/usertoken/client.go new file mode 100644 index 00000000000..adeb6294866 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usertoken/client.go @@ -0,0 +1,26 @@ +package usertoken + +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 UserTokenClient struct { + Client *resourcemanager.Client +} + +func NewUserTokenClientWithBaseURI(sdkApi sdkEnv.Api) (*UserTokenClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "usertoken", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating UserTokenClient: %+v", err) + } + + return &UserTokenClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/usertoken/constants.go b/resource-manager/apimanagement/2024-05-01/usertoken/constants.go new file mode 100644 index 00000000000..9c811483fc3 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usertoken/constants.go @@ -0,0 +1,51 @@ +package usertoken + +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 KeyType string + +const ( + KeyTypePrimary KeyType = "primary" + KeyTypeSecondary KeyType = "secondary" +) + +func PossibleValuesForKeyType() []string { + return []string{ + string(KeyTypePrimary), + string(KeyTypeSecondary), + } +} + +func (s *KeyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKeyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseKeyType(input string) (*KeyType, error) { + vals := map[string]KeyType{ + "primary": KeyTypePrimary, + "secondary": KeyTypeSecondary, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := KeyType(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/usertoken/id_user.go b/resource-manager/apimanagement/2024-05-01/usertoken/id_user.go new file mode 100644 index 00000000000..e0f7cf9ee4b --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usertoken/id_user.go @@ -0,0 +1,139 @@ +package usertoken + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&UserId{}) +} + +var _ resourceids.ResourceId = &UserId{} + +// UserId is a struct representing the Resource ID for a User +type UserId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + UserId string +} + +// NewUserID returns a new UserId struct +func NewUserID(subscriptionId string, resourceGroupName string, serviceName string, userId string) UserId { + return UserId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + UserId: userId, + } +} + +// ParseUserID parses 'input' into a UserId +func ParseUserID(input string) (*UserId, error) { + parser := resourceids.NewParserFromResourceIdType(&UserId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UserId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseUserIDInsensitively parses 'input' case-insensitively into a UserId +// note: this method should only be used for API response data and not user input +func ParseUserIDInsensitively(input string) (*UserId, error) { + parser := resourceids.NewParserFromResourceIdType(&UserId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UserId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *UserId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.UserId, ok = input.Parsed["userId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "userId", input) + } + + return nil +} + +// ValidateUserID checks that 'input' can be parsed as a User ID +func ValidateUserID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseUserID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted User ID +func (id UserId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/users/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.UserId) +} + +// Segments returns a slice of Resource ID Segments which comprise this User ID +func (id UserId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticUsers", "users", "users"), + resourceids.UserSpecifiedSegment("userId", "userIdValue"), + } +} + +// String returns a human-readable description of this User ID +func (id UserId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("User: %q", id.UserId), + } + return fmt.Sprintf("User (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/usertoken/id_user_test.go b/resource-manager/apimanagement/2024-05-01/usertoken/id_user_test.go new file mode 100644 index 00000000000..533992af005 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usertoken/id_user_test.go @@ -0,0 +1,327 @@ +package usertoken + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &UserId{} + +func TestNewUserID(t *testing.T) { + id := NewUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.UserId != "userIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'UserId'", id.UserId, "userIdValue") + } +} + +func TestFormatUserID(t *testing.T) { + actual := NewUserID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "userIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseUserID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UserId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue", + Expected: &UserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + UserId: "userIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUserID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.UserId != v.Expected.UserId { + t.Fatalf("Expected %q but got %q for UserId", v.Expected.UserId, actual.UserId) + } + + } +} + +func TestParseUserIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UserId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue", + Expected: &UserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + UserId: "userIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/users/userIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs/uSeRiDvAlUe", + Expected: &UserId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + UserId: "uSeRiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/uSeRs/uSeRiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUserIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.UserId != v.Expected.UserId { + t.Fatalf("Expected %q but got %q for UserId", v.Expected.UserId, actual.UserId) + } + + } +} + +func TestSegmentsForUserId(t *testing.T) { + segments := UserId{}.Segments() + if len(segments) == 0 { + t.Fatalf("UserId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/usertoken/method_usergetsharedaccesstoken.go b/resource-manager/apimanagement/2024-05-01/usertoken/method_usergetsharedaccesstoken.go new file mode 100644 index 00000000000..28e0efb393e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usertoken/method_usergetsharedaccesstoken.go @@ -0,0 +1,59 @@ +package usertoken + +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 UserGetSharedAccessTokenOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *UserTokenResult +} + +// UserGetSharedAccessToken ... +func (c UserTokenClient) UserGetSharedAccessToken(ctx context.Context, id UserId, input UserTokenParameters) (result UserGetSharedAccessTokenOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/token", 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 UserTokenResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/usertoken/model_usertokenparameterproperties.go b/resource-manager/apimanagement/2024-05-01/usertoken/model_usertokenparameterproperties.go new file mode 100644 index 00000000000..b29b67ea595 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usertoken/model_usertokenparameterproperties.go @@ -0,0 +1,24 @@ +package usertoken + +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 UserTokenParameterProperties struct { + Expiry string `json:"expiry"` + KeyType KeyType `json:"keyType"` +} + +func (o *UserTokenParameterProperties) GetExpiryAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.Expiry, "2006-01-02T15:04:05Z07:00") +} + +func (o *UserTokenParameterProperties) SetExpiryAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Expiry = formatted +} diff --git a/resource-manager/apimanagement/2024-05-01/usertoken/model_usertokenparameters.go b/resource-manager/apimanagement/2024-05-01/usertoken/model_usertokenparameters.go new file mode 100644 index 00000000000..8ccb144fcc9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usertoken/model_usertokenparameters.go @@ -0,0 +1,8 @@ +package usertoken + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserTokenParameters struct { + Properties *UserTokenParameterProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/usertoken/model_usertokenresult.go b/resource-manager/apimanagement/2024-05-01/usertoken/model_usertokenresult.go new file mode 100644 index 00000000000..ae393896a9e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usertoken/model_usertokenresult.go @@ -0,0 +1,8 @@ +package usertoken + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserTokenResult struct { + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/usertoken/version.go b/resource-manager/apimanagement/2024-05-01/usertoken/version.go new file mode 100644 index 00000000000..b282b50cb9a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/usertoken/version.go @@ -0,0 +1,12 @@ +package usertoken + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/usertoken/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/workspace/README.md b/resource-manager/apimanagement/2024-05-01/workspace/README.md new file mode 100644 index 00000000000..dc45515bc62 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspace/README.md @@ -0,0 +1,127 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/workspace` Documentation + +The `workspace` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/workspace" +``` + + +### Client Initialization + +```go +client := workspace.NewWorkspaceClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `WorkspaceClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := workspace.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +payload := workspace.WorkspaceContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, workspace.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspaceClient.Delete` + +```go +ctx := context.TODO() +id := workspace.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +read, err := client.Delete(ctx, id, workspace.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspaceClient.Get` + +```go +ctx := context.TODO() +id := workspace.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +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: `WorkspaceClient.GetEntityTag` + +```go +ctx := context.TODO() +id := workspace.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspaceClient.ListByService` + +```go +ctx := context.TODO() +id := workspace.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.ListByService(ctx, id, workspace.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, workspace.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `WorkspaceClient.Update` + +```go +ctx := context.TODO() +id := workspace.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +payload := workspace.WorkspaceContract{ + // ... +} + + +read, err := client.Update(ctx, id, payload, workspace.DefaultUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/workspace/client.go b/resource-manager/apimanagement/2024-05-01/workspace/client.go new file mode 100644 index 00000000000..183f0254ebd --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspace/client.go @@ -0,0 +1,26 @@ +package workspace + +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 WorkspaceClient struct { + Client *resourcemanager.Client +} + +func NewWorkspaceClientWithBaseURI(sdkApi sdkEnv.Api) (*WorkspaceClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "workspace", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WorkspaceClient: %+v", err) + } + + return &WorkspaceClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/workspace/id_service.go b/resource-manager/apimanagement/2024-05-01/workspace/id_service.go new file mode 100644 index 00000000000..8d9a4894f5c --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspace/id_service.go @@ -0,0 +1,130 @@ +package workspace + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/workspace/id_service_test.go b/resource-manager/apimanagement/2024-05-01/workspace/id_service_test.go new file mode 100644 index 00000000000..20fc412dd3d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspace/id_service_test.go @@ -0,0 +1,282 @@ +package workspace + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ServiceId{} + +func TestNewServiceID(t *testing.T) { + id := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } +} + +func TestFormatServiceID(t *testing.T) { + actual := NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestParseServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Expected: &ServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + } +} + +func TestSegmentsForServiceId(t *testing.T) { + segments := ServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/workspace/id_workspace.go b/resource-manager/apimanagement/2024-05-01/workspace/id_workspace.go new file mode 100644 index 00000000000..d86572af484 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspace/id_workspace.go @@ -0,0 +1,139 @@ +package workspace + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/workspace/id_workspace_test.go b/resource-manager/apimanagement/2024-05-01/workspace/id_workspace_test.go new file mode 100644 index 00000000000..e7b989072b0 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspace/id_workspace_test.go @@ -0,0 +1,327 @@ +package workspace + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/workspace/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/workspace/method_createorupdate.go new file mode 100644 index 00000000000..dfbaee168e5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspace/method_createorupdate.go @@ -0,0 +1,88 @@ +package workspace + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WorkspaceContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c WorkspaceClient) CreateOrUpdate(ctx context.Context, id WorkspaceId, input WorkspaceContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 WorkspaceContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/workspace/method_delete.go b/resource-manager/apimanagement/2024-05-01/workspace/method_delete.go new file mode 100644 index 00000000000..41a2b818416 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspace/method_delete.go @@ -0,0 +1,76 @@ +package workspace + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c WorkspaceClient) Delete(ctx context.Context, id WorkspaceId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/workspace/method_get.go b/resource-manager/apimanagement/2024-05-01/workspace/method_get.go new file mode 100644 index 00000000000..2bea0d0912a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspace/method_get.go @@ -0,0 +1,54 @@ +package workspace + +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 *WorkspaceContract +} + +// Get ... +func (c WorkspaceClient) Get(ctx context.Context, id WorkspaceId) (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 WorkspaceContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/workspace/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/workspace/method_getentitytag.go new file mode 100644 index 00000000000..dc596dad4f5 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspace/method_getentitytag.go @@ -0,0 +1,46 @@ +package workspace + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c WorkspaceClient) GetEntityTag(ctx context.Context, id WorkspaceId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/workspace/method_listbyservice.go b/resource-manager/apimanagement/2024-05-01/workspace/method_listbyservice.go new file mode 100644 index 00000000000..d7edc0c9746 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspace/method_listbyservice.go @@ -0,0 +1,141 @@ +package workspace + +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 ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]WorkspaceContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []WorkspaceContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c WorkspaceClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/workspaces", 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 *[]WorkspaceContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c WorkspaceClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, WorkspaceContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WorkspaceClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate WorkspaceContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]WorkspaceContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/workspace/method_update.go b/resource-manager/apimanagement/2024-05-01/workspace/method_update.go new file mode 100644 index 00000000000..840713f4a4f --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspace/method_update.go @@ -0,0 +1,87 @@ +package workspace + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WorkspaceContract +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c WorkspaceClient) Update(ctx context.Context, id WorkspaceId, input WorkspaceContract, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 WorkspaceContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/workspace/model_workspacecontract.go b/resource-manager/apimanagement/2024-05-01/workspace/model_workspacecontract.go new file mode 100644 index 00000000000..14ed98ac77e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspace/model_workspacecontract.go @@ -0,0 +1,11 @@ +package workspace + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *WorkspaceContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/workspace/model_workspacecontractproperties.go b/resource-manager/apimanagement/2024-05-01/workspace/model_workspacecontractproperties.go new file mode 100644 index 00000000000..2b2d6b2c80e --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspace/model_workspacecontractproperties.go @@ -0,0 +1,9 @@ +package workspace + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceContractProperties struct { + Description *string `json:"description,omitempty"` + DisplayName string `json:"displayName"` +} diff --git a/resource-manager/apimanagement/2024-05-01/workspace/predicates.go b/resource-manager/apimanagement/2024-05-01/workspace/predicates.go new file mode 100644 index 00000000000..7a1c20ebdc2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspace/predicates.go @@ -0,0 +1,27 @@ +package workspace + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p WorkspaceContractOperationPredicate) Matches(input WorkspaceContract) 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/apimanagement/2024-05-01/workspace/version.go b/resource-manager/apimanagement/2024-05-01/workspace/version.go new file mode 100644 index 00000000000..137a79edbd4 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspace/version.go @@ -0,0 +1,12 @@ +package workspace + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/workspace/%s", defaultApiVersion) +} diff --git a/resource-manager/apimanagement/2024-05-01/workspacepolicy/README.md b/resource-manager/apimanagement/2024-05-01/workspacepolicy/README.md new file mode 100644 index 00000000000..17c3c2a2af6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspacepolicy/README.md @@ -0,0 +1,106 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/workspacepolicy` Documentation + +The `workspacepolicy` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/workspacepolicy" +``` + + +### Client Initialization + +```go +client := workspacepolicy.NewWorkspacePolicyClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `WorkspacePolicyClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := workspacepolicy.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +payload := workspacepolicy.PolicyContract{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, workspacepolicy.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspacePolicyClient.Delete` + +```go +ctx := context.TODO() +id := workspacepolicy.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +read, err := client.Delete(ctx, id, workspacepolicy.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspacePolicyClient.Get` + +```go +ctx := context.TODO() +id := workspacepolicy.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +read, err := client.Get(ctx, id, workspacepolicy.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspacePolicyClient.GetEntityTag` + +```go +ctx := context.TODO() +id := workspacepolicy.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspacePolicyClient.ListByApi` + +```go +ctx := context.TODO() +id := workspacepolicy.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + +// alternatively `client.ListByApi(ctx, id)` can be used to do batched pagination +items, err := client.ListByApiComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/apimanagement/2024-05-01/workspacepolicy/client.go b/resource-manager/apimanagement/2024-05-01/workspacepolicy/client.go new file mode 100644 index 00000000000..d4e3c38bc31 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspacepolicy/client.go @@ -0,0 +1,26 @@ +package workspacepolicy + +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 WorkspacePolicyClient struct { + Client *resourcemanager.Client +} + +func NewWorkspacePolicyClientWithBaseURI(sdkApi sdkEnv.Api) (*WorkspacePolicyClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "workspacepolicy", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WorkspacePolicyClient: %+v", err) + } + + return &WorkspacePolicyClient{ + Client: client, + }, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/workspacepolicy/constants.go b/resource-manager/apimanagement/2024-05-01/workspacepolicy/constants.go new file mode 100644 index 00000000000..99b8bd1db2d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspacepolicy/constants.go @@ -0,0 +1,98 @@ +package workspacepolicy + +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 PolicyContentFormat string + +const ( + PolicyContentFormatRawxml PolicyContentFormat = "rawxml" + PolicyContentFormatRawxmlNegativelink PolicyContentFormat = "rawxml-link" + PolicyContentFormatXml PolicyContentFormat = "xml" + PolicyContentFormatXmlNegativelink PolicyContentFormat = "xml-link" +) + +func PossibleValuesForPolicyContentFormat() []string { + return []string{ + string(PolicyContentFormatRawxml), + string(PolicyContentFormatRawxmlNegativelink), + string(PolicyContentFormatXml), + string(PolicyContentFormatXmlNegativelink), + } +} + +func (s *PolicyContentFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePolicyContentFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePolicyContentFormat(input string) (*PolicyContentFormat, error) { + vals := map[string]PolicyContentFormat{ + "rawxml": PolicyContentFormatRawxml, + "rawxml-link": PolicyContentFormatRawxmlNegativelink, + "xml": PolicyContentFormatXml, + "xml-link": PolicyContentFormatXmlNegativelink, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyContentFormat(input) + return &out, nil +} + +type PolicyExportFormat string + +const ( + PolicyExportFormatRawxml PolicyExportFormat = "rawxml" + PolicyExportFormatXml PolicyExportFormat = "xml" +) + +func PossibleValuesForPolicyExportFormat() []string { + return []string{ + string(PolicyExportFormatRawxml), + string(PolicyExportFormatXml), + } +} + +func (s *PolicyExportFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePolicyExportFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePolicyExportFormat(input string) (*PolicyExportFormat, error) { + vals := map[string]PolicyExportFormat{ + "rawxml": PolicyExportFormatRawxml, + "xml": PolicyExportFormatXml, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyExportFormat(input) + return &out, nil +} diff --git a/resource-manager/apimanagement/2024-05-01/workspacepolicy/id_workspace.go b/resource-manager/apimanagement/2024-05-01/workspacepolicy/id_workspace.go new file mode 100644 index 00000000000..12c8b423579 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspacepolicy/id_workspace.go @@ -0,0 +1,139 @@ +package workspacepolicy + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceIdValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/apimanagement/2024-05-01/workspacepolicy/id_workspace_test.go b/resource-manager/apimanagement/2024-05-01/workspacepolicy/id_workspace_test.go new file mode 100644 index 00000000000..f9bf5cf57a8 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspacepolicy/id_workspace_test.go @@ -0,0 +1,327 @@ +package workspacepolicy + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServiceName != "serviceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServiceName'", id.ServiceName, "serviceValue") + } + + if id.WorkspaceId != "workspaceIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceId'", id.WorkspaceId, "workspaceIdValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "workspaceIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServiceName: "serviceValue", + WorkspaceId: "workspaceIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/workspaces/workspaceIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServiceName: "sErViCeVaLuE", + WorkspaceId: "wOrKsPaCeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPiMaNaGeMeNt/sErViCe/sErViCeVaLuE/wOrKsPaCeS/wOrKsPaCeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServiceName != v.Expected.ServiceName { + t.Fatalf("Expected %q but got %q for ServiceName", v.Expected.ServiceName, actual.ServiceName) + } + + if actual.WorkspaceId != v.Expected.WorkspaceId { + t.Fatalf("Expected %q but got %q for WorkspaceId", v.Expected.WorkspaceId, actual.WorkspaceId) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/apimanagement/2024-05-01/workspacepolicy/method_createorupdate.go b/resource-manager/apimanagement/2024-05-01/workspacepolicy/method_createorupdate.go new file mode 100644 index 00000000000..9385b41a924 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspacepolicy/method_createorupdate.go @@ -0,0 +1,88 @@ +package workspacepolicy + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c WorkspacePolicyClient) CreateOrUpdate(ctx context.Context, id WorkspaceId, input PolicyContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", 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 PolicyContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/workspacepolicy/method_delete.go b/resource-manager/apimanagement/2024-05-01/workspacepolicy/method_delete.go new file mode 100644 index 00000000000..ac1ad5e7365 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspacepolicy/method_delete.go @@ -0,0 +1,76 @@ +package workspacepolicy + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c WorkspacePolicyClient) Delete(ctx context.Context, id WorkspaceId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/workspacepolicy/method_get.go b/resource-manager/apimanagement/2024-05-01/workspacepolicy/method_get.go new file mode 100644 index 00000000000..90e7b0877f6 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspacepolicy/method_get.go @@ -0,0 +1,83 @@ +package workspacepolicy + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyContract +} + +type GetOperationOptions struct { + Format *PolicyExportFormat +} + +func DefaultGetOperationOptions() GetOperationOptions { + return GetOperationOptions{} +} + +func (o GetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o GetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o GetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Format != nil { + out.Append("format", fmt.Sprintf("%v", *o.Format)) + } + return &out +} + +// Get ... +func (c WorkspacePolicyClient) Get(ctx context.Context, id WorkspaceId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/policies/policy", 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 PolicyContract + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/workspacepolicy/method_getentitytag.go b/resource-manager/apimanagement/2024-05-01/workspacepolicy/method_getentitytag.go new file mode 100644 index 00000000000..2dcb1fcf0ae --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspacepolicy/method_getentitytag.go @@ -0,0 +1,47 @@ +package workspacepolicy + +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 GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c WorkspacePolicyClient) GetEntityTag(ctx context.Context, id WorkspaceId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: fmt.Sprintf("%s/policies/policy", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/apimanagement/2024-05-01/workspacepolicy/method_listbyapi.go b/resource-manager/apimanagement/2024-05-01/workspacepolicy/method_listbyapi.go new file mode 100644 index 00000000000..c09f736cf9a --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspacepolicy/method_listbyapi.go @@ -0,0 +1,105 @@ +package workspacepolicy + +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 ListByApiOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PolicyContract +} + +type ListByApiCompleteResult struct { + LatestHttpResponse *http.Response + Items []PolicyContract +} + +type ListByApiCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByApiCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByApi ... +func (c WorkspacePolicyClient) ListByApi(ctx context.Context, id WorkspaceId) (result ListByApiOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByApiCustomPager{}, + Path: fmt.Sprintf("%s/policies", 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 *[]PolicyContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByApiComplete retrieves all the results into a single object +func (c WorkspacePolicyClient) ListByApiComplete(ctx context.Context, id WorkspaceId) (ListByApiCompleteResult, error) { + return c.ListByApiCompleteMatchingPredicate(ctx, id, PolicyContractOperationPredicate{}) +} + +// ListByApiCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WorkspacePolicyClient) ListByApiCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate PolicyContractOperationPredicate) (result ListByApiCompleteResult, err error) { + items := make([]PolicyContract, 0) + + resp, err := c.ListByApi(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByApiCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/apimanagement/2024-05-01/workspacepolicy/model_policycontract.go b/resource-manager/apimanagement/2024-05-01/workspacepolicy/model_policycontract.go new file mode 100644 index 00000000000..d0958c5474d --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspacepolicy/model_policycontract.go @@ -0,0 +1,11 @@ +package workspacepolicy + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PolicyContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/apimanagement/2024-05-01/workspacepolicy/model_policycontractproperties.go b/resource-manager/apimanagement/2024-05-01/workspacepolicy/model_policycontractproperties.go new file mode 100644 index 00000000000..c98480378f9 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspacepolicy/model_policycontractproperties.go @@ -0,0 +1,9 @@ +package workspacepolicy + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyContractProperties struct { + Format *PolicyContentFormat `json:"format,omitempty"` + Value string `json:"value"` +} diff --git a/resource-manager/apimanagement/2024-05-01/workspacepolicy/predicates.go b/resource-manager/apimanagement/2024-05-01/workspacepolicy/predicates.go new file mode 100644 index 00000000000..f32f541d6e2 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspacepolicy/predicates.go @@ -0,0 +1,27 @@ +package workspacepolicy + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PolicyContractOperationPredicate) Matches(input PolicyContract) 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/apimanagement/2024-05-01/workspacepolicy/version.go b/resource-manager/apimanagement/2024-05-01/workspacepolicy/version.go new file mode 100644 index 00000000000..833ad688252 --- /dev/null +++ b/resource-manager/apimanagement/2024-05-01/workspacepolicy/version.go @@ -0,0 +1,12 @@ +package workspacepolicy + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/workspacepolicy/%s", defaultApiVersion) +} diff --git a/resource-manager/datafactory/2018-06-01/linkedservices/model_mariadblinkedservicetypeproperties.go b/resource-manager/datafactory/2018-06-01/linkedservices/model_mariadblinkedservicetypeproperties.go index 664f0c53b99..ab4a25aba49 100644 --- a/resource-manager/datafactory/2018-06-01/linkedservices/model_mariadblinkedservicetypeproperties.go +++ b/resource-manager/datafactory/2018-06-01/linkedservices/model_mariadblinkedservicetypeproperties.go @@ -11,5 +11,7 @@ type MariaDBLinkedServiceTypeProperties struct { Password *AzureKeyVaultSecretReference `json:"password,omitempty"` Port *int64 `json:"port,omitempty"` Server *string `json:"server,omitempty"` + SslMode *int64 `json:"sslMode,omitempty"` + UseSystemTrustStore *int64 `json:"useSystemTrustStore,omitempty"` Username *string `json:"username,omitempty"` } diff --git a/resource-manager/nginx/2024-06-01-preview/client.go b/resource-manager/nginx/2024-06-01-preview/client.go new file mode 100644 index 00000000000..cc6457e0b03 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/client.go @@ -0,0 +1,55 @@ +package v2024_06_01_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/nginx/2024-06-01-preview/nginxcertificate" + "github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-06-01-preview/nginxconfiguration" + "github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis" + "github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-06-01-preview/nginxdeployment" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + NginxCertificate *nginxcertificate.NginxCertificateClient + NginxConfiguration *nginxconfiguration.NginxConfigurationClient + NginxConfigurationAnalysis *nginxconfigurationanalysis.NginxConfigurationAnalysisClient + NginxDeployment *nginxdeployment.NginxDeploymentClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + nginxCertificateClient, err := nginxcertificate.NewNginxCertificateClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building NginxCertificate client: %+v", err) + } + configureFunc(nginxCertificateClient.Client) + + nginxConfigurationAnalysisClient, err := nginxconfigurationanalysis.NewNginxConfigurationAnalysisClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building NginxConfigurationAnalysis client: %+v", err) + } + configureFunc(nginxConfigurationAnalysisClient.Client) + + nginxConfigurationClient, err := nginxconfiguration.NewNginxConfigurationClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building NginxConfiguration client: %+v", err) + } + configureFunc(nginxConfigurationClient.Client) + + nginxDeploymentClient, err := nginxdeployment.NewNginxDeploymentClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building NginxDeployment client: %+v", err) + } + configureFunc(nginxDeploymentClient.Client) + + return &Client{ + NginxCertificate: nginxCertificateClient, + NginxConfiguration: nginxConfigurationClient, + NginxConfigurationAnalysis: nginxConfigurationAnalysisClient, + NginxDeployment: nginxDeploymentClient, + }, nil +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxcertificate/README.md b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/README.md new file mode 100644 index 00000000000..b96160dec15 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-06-01-preview/nginxcertificate` Documentation + +The `nginxcertificate` SDK allows for interaction with the Azure Resource Manager Service `nginx` (API Version `2024-06-01-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/nginx/2024-06-01-preview/nginxcertificate" +``` + + +### Client Initialization + +```go +client := nginxcertificate.NewNginxCertificateClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `NginxCertificateClient.CertificatesCreateOrUpdate` + +```go +ctx := context.TODO() +id := nginxcertificate.NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue", "certificateValue") + +payload := nginxcertificate.NginxCertificate{ + // ... +} + + +if err := client.CertificatesCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `NginxCertificateClient.CertificatesDelete` + +```go +ctx := context.TODO() +id := nginxcertificate.NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue", "certificateValue") + +if err := client.CertificatesDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `NginxCertificateClient.CertificatesGet` + +```go +ctx := context.TODO() +id := nginxcertificate.NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue", "certificateValue") + +read, err := client.CertificatesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NginxCertificateClient.CertificatesList` + +```go +ctx := context.TODO() +id := nginxcertificate.NewNginxDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue") + +// alternatively `client.CertificatesList(ctx, id)` can be used to do batched pagination +items, err := client.CertificatesListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/nginx/2024-06-01-preview/nginxcertificate/client.go b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/client.go new file mode 100644 index 00000000000..afeaf1e338a --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/client.go @@ -0,0 +1,26 @@ +package nginxcertificate + +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 NginxCertificateClient struct { + Client *resourcemanager.Client +} + +func NewNginxCertificateClientWithBaseURI(sdkApi sdkEnv.Api) (*NginxCertificateClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "nginxcertificate", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating NginxCertificateClient: %+v", err) + } + + return &NginxCertificateClient{ + Client: client, + }, nil +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxcertificate/constants.go b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/constants.go new file mode 100644 index 00000000000..5cea630d9fe --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/constants.go @@ -0,0 +1,72 @@ +package nginxcertificate + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "notspecified": ProvisioningStateNotSpecified, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxcertificate/id_certificate.go b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/id_certificate.go new file mode 100644 index 00000000000..cce2197f7fd --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/id_certificate.go @@ -0,0 +1,139 @@ +package nginxcertificate + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&CertificateId{}) +} + +var _ resourceids.ResourceId = &CertificateId{} + +// CertificateId is a struct representing the Resource ID for a Certificate +type CertificateId struct { + SubscriptionId string + ResourceGroupName string + NginxDeploymentName string + CertificateName string +} + +// NewCertificateID returns a new CertificateId struct +func NewCertificateID(subscriptionId string, resourceGroupName string, nginxDeploymentName string, certificateName string) CertificateId { + return CertificateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + NginxDeploymentName: nginxDeploymentName, + CertificateName: certificateName, + } +} + +// ParseCertificateID parses 'input' into a CertificateId +func ParseCertificateID(input string) (*CertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(&CertificateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CertificateId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseCertificateIDInsensitively parses 'input' case-insensitively into a CertificateId +// note: this method should only be used for API response data and not user input +func ParseCertificateIDInsensitively(input string) (*CertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(&CertificateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CertificateId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *CertificateId) 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.NginxDeploymentName, ok = input.Parsed["nginxDeploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "nginxDeploymentName", input) + } + + if id.CertificateName, ok = input.Parsed["certificateName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "certificateName", input) + } + + return nil +} + +// ValidateCertificateID checks that 'input' can be parsed as a Certificate ID +func ValidateCertificateID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseCertificateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Certificate ID +func (id CertificateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Nginx.NginxPlus/nginxDeployments/%s/certificates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.NginxDeploymentName, id.CertificateName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Certificate ID +func (id CertificateId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticNginxNginxPlus", "Nginx.NginxPlus", "Nginx.NginxPlus"), + resourceids.StaticSegment("staticNginxDeployments", "nginxDeployments", "nginxDeployments"), + resourceids.UserSpecifiedSegment("nginxDeploymentName", "nginxDeploymentValue"), + resourceids.StaticSegment("staticCertificates", "certificates", "certificates"), + resourceids.UserSpecifiedSegment("certificateName", "certificateValue"), + } +} + +// String returns a human-readable description of this Certificate ID +func (id CertificateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Nginx Deployment Name: %q", id.NginxDeploymentName), + fmt.Sprintf("Certificate Name: %q", id.CertificateName), + } + return fmt.Sprintf("Certificate (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxcertificate/id_certificate_test.go b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/id_certificate_test.go new file mode 100644 index 00000000000..79991d6321b --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/id_certificate_test.go @@ -0,0 +1,327 @@ +package nginxcertificate + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &CertificateId{} + +func TestNewCertificateID(t *testing.T) { + id := NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue", "certificateValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.NginxDeploymentName != "nginxDeploymentValue" { + t.Fatalf("Expected %q but got %q for Segment 'NginxDeploymentName'", id.NginxDeploymentName, "nginxDeploymentValue") + } + + if id.CertificateName != "certificateValue" { + t.Fatalf("Expected %q but got %q for Segment 'CertificateName'", id.CertificateName, "certificateValue") + } +} + +func TestFormatCertificateID(t *testing.T) { + actual := NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue", "certificateValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/certificates/certificateValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCertificateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CertificateId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/certificates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/certificates/certificateValue", + Expected: &CertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NginxDeploymentName: "nginxDeploymentValue", + CertificateName: "certificateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/certificates/certificateValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCertificateID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NginxDeploymentName != v.Expected.NginxDeploymentName { + t.Fatalf("Expected %q but got %q for NginxDeploymentName", v.Expected.NginxDeploymentName, actual.NginxDeploymentName) + } + + if actual.CertificateName != v.Expected.CertificateName { + t.Fatalf("Expected %q but got %q for CertificateName", v.Expected.CertificateName, actual.CertificateName) + } + + } +} + +func TestParseCertificateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CertificateId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs/nGiNxDePlOyMeNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs/nGiNxDePlOyMeNtS/nGiNxDePlOyMeNtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/certificates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs/nGiNxDePlOyMeNtS/nGiNxDePlOyMeNtVaLuE/cErTiFiCaTeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/certificates/certificateValue", + Expected: &CertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NginxDeploymentName: "nginxDeploymentValue", + CertificateName: "certificateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/certificates/certificateValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs/nGiNxDePlOyMeNtS/nGiNxDePlOyMeNtVaLuE/cErTiFiCaTeS/cErTiFiCaTeVaLuE", + Expected: &CertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + NginxDeploymentName: "nGiNxDePlOyMeNtVaLuE", + CertificateName: "cErTiFiCaTeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs/nGiNxDePlOyMeNtS/nGiNxDePlOyMeNtVaLuE/cErTiFiCaTeS/cErTiFiCaTeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCertificateIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NginxDeploymentName != v.Expected.NginxDeploymentName { + t.Fatalf("Expected %q but got %q for NginxDeploymentName", v.Expected.NginxDeploymentName, actual.NginxDeploymentName) + } + + if actual.CertificateName != v.Expected.CertificateName { + t.Fatalf("Expected %q but got %q for CertificateName", v.Expected.CertificateName, actual.CertificateName) + } + + } +} + +func TestSegmentsForCertificateId(t *testing.T) { + segments := CertificateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CertificateId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxcertificate/id_nginxdeployment.go b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/id_nginxdeployment.go new file mode 100644 index 00000000000..be10f98b557 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/id_nginxdeployment.go @@ -0,0 +1,130 @@ +package nginxcertificate + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&NginxDeploymentId{}) +} + +var _ resourceids.ResourceId = &NginxDeploymentId{} + +// NginxDeploymentId is a struct representing the Resource ID for a Nginx Deployment +type NginxDeploymentId struct { + SubscriptionId string + ResourceGroupName string + NginxDeploymentName string +} + +// NewNginxDeploymentID returns a new NginxDeploymentId struct +func NewNginxDeploymentID(subscriptionId string, resourceGroupName string, nginxDeploymentName string) NginxDeploymentId { + return NginxDeploymentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + NginxDeploymentName: nginxDeploymentName, + } +} + +// ParseNginxDeploymentID parses 'input' into a NginxDeploymentId +func ParseNginxDeploymentID(input string) (*NginxDeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&NginxDeploymentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NginxDeploymentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNginxDeploymentIDInsensitively parses 'input' case-insensitively into a NginxDeploymentId +// note: this method should only be used for API response data and not user input +func ParseNginxDeploymentIDInsensitively(input string) (*NginxDeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&NginxDeploymentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NginxDeploymentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NginxDeploymentId) 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.NginxDeploymentName, ok = input.Parsed["nginxDeploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "nginxDeploymentName", input) + } + + return nil +} + +// ValidateNginxDeploymentID checks that 'input' can be parsed as a Nginx Deployment ID +func ValidateNginxDeploymentID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseNginxDeploymentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Nginx Deployment ID +func (id NginxDeploymentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Nginx.NginxPlus/nginxDeployments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.NginxDeploymentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Nginx Deployment ID +func (id NginxDeploymentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticNginxNginxPlus", "Nginx.NginxPlus", "Nginx.NginxPlus"), + resourceids.StaticSegment("staticNginxDeployments", "nginxDeployments", "nginxDeployments"), + resourceids.UserSpecifiedSegment("nginxDeploymentName", "nginxDeploymentValue"), + } +} + +// String returns a human-readable description of this Nginx Deployment ID +func (id NginxDeploymentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Nginx Deployment Name: %q", id.NginxDeploymentName), + } + return fmt.Sprintf("Nginx Deployment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxcertificate/id_nginxdeployment_test.go b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/id_nginxdeployment_test.go new file mode 100644 index 00000000000..6728a9958a3 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/id_nginxdeployment_test.go @@ -0,0 +1,282 @@ +package nginxcertificate + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &NginxDeploymentId{} + +func TestNewNginxDeploymentID(t *testing.T) { + id := NewNginxDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.NginxDeploymentName != "nginxDeploymentValue" { + t.Fatalf("Expected %q but got %q for Segment 'NginxDeploymentName'", id.NginxDeploymentName, "nginxDeploymentValue") + } +} + +func TestFormatNginxDeploymentID(t *testing.T) { + actual := NewNginxDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNginxDeploymentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NginxDeploymentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue", + Expected: &NginxDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NginxDeploymentName: "nginxDeploymentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNginxDeploymentID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NginxDeploymentName != v.Expected.NginxDeploymentName { + t.Fatalf("Expected %q but got %q for NginxDeploymentName", v.Expected.NginxDeploymentName, actual.NginxDeploymentName) + } + + } +} + +func TestParseNginxDeploymentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NginxDeploymentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs/nGiNxDePlOyMeNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue", + Expected: &NginxDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NginxDeploymentName: "nginxDeploymentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs/nGiNxDePlOyMeNtS/nGiNxDePlOyMeNtVaLuE", + Expected: &NginxDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + NginxDeploymentName: "nGiNxDePlOyMeNtVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs/nGiNxDePlOyMeNtS/nGiNxDePlOyMeNtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNginxDeploymentIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NginxDeploymentName != v.Expected.NginxDeploymentName { + t.Fatalf("Expected %q but got %q for NginxDeploymentName", v.Expected.NginxDeploymentName, actual.NginxDeploymentName) + } + + } +} + +func TestSegmentsForNginxDeploymentId(t *testing.T) { + segments := NginxDeploymentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NginxDeploymentId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxcertificate/method_certificatescreateorupdate.go b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/method_certificatescreateorupdate.go new file mode 100644 index 00000000000..2a7b5830e86 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/method_certificatescreateorupdate.go @@ -0,0 +1,75 @@ +package nginxcertificate + +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 CertificatesCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *NginxCertificate +} + +// CertificatesCreateOrUpdate ... +func (c NginxCertificateClient) CertificatesCreateOrUpdate(ctx context.Context, id CertificateId, input NginxCertificate) (result CertificatesCreateOrUpdateOperationResponse, 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 +} + +// CertificatesCreateOrUpdateThenPoll performs CertificatesCreateOrUpdate then polls until it's completed +func (c NginxCertificateClient) CertificatesCreateOrUpdateThenPoll(ctx context.Context, id CertificateId, input NginxCertificate) error { + result, err := c.CertificatesCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CertificatesCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CertificatesCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxcertificate/method_certificatesdelete.go b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/method_certificatesdelete.go new file mode 100644 index 00000000000..2e68fad4bb8 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/method_certificatesdelete.go @@ -0,0 +1,71 @@ +package nginxcertificate + +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 CertificatesDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// CertificatesDelete ... +func (c NginxCertificateClient) CertificatesDelete(ctx context.Context, id CertificateId) (result CertificatesDeleteOperationResponse, 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 +} + +// CertificatesDeleteThenPoll performs CertificatesDelete then polls until it's completed +func (c NginxCertificateClient) CertificatesDeleteThenPoll(ctx context.Context, id CertificateId) error { + result, err := c.CertificatesDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing CertificatesDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CertificatesDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxcertificate/method_certificatesget.go b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/method_certificatesget.go new file mode 100644 index 00000000000..6b8832d8eb6 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/method_certificatesget.go @@ -0,0 +1,54 @@ +package nginxcertificate + +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 CertificatesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *NginxCertificate +} + +// CertificatesGet ... +func (c NginxCertificateClient) CertificatesGet(ctx context.Context, id CertificateId) (result CertificatesGetOperationResponse, 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 NginxCertificate + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxcertificate/method_certificateslist.go b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/method_certificateslist.go new file mode 100644 index 00000000000..759cf53eb4f --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/method_certificateslist.go @@ -0,0 +1,105 @@ +package nginxcertificate + +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 CertificatesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]NginxCertificate +} + +type CertificatesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []NginxCertificate +} + +type CertificatesListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *CertificatesListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// CertificatesList ... +func (c NginxCertificateClient) CertificatesList(ctx context.Context, id NginxDeploymentId) (result CertificatesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &CertificatesListCustomPager{}, + Path: fmt.Sprintf("%s/certificates", 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 *[]NginxCertificate `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// CertificatesListComplete retrieves all the results into a single object +func (c NginxCertificateClient) CertificatesListComplete(ctx context.Context, id NginxDeploymentId) (CertificatesListCompleteResult, error) { + return c.CertificatesListCompleteMatchingPredicate(ctx, id, NginxCertificateOperationPredicate{}) +} + +// CertificatesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c NginxCertificateClient) CertificatesListCompleteMatchingPredicate(ctx context.Context, id NginxDeploymentId, predicate NginxCertificateOperationPredicate) (result CertificatesListCompleteResult, err error) { + items := make([]NginxCertificate, 0) + + resp, err := c.CertificatesList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = CertificatesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxcertificate/model_nginxcertificate.go b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/model_nginxcertificate.go new file mode 100644 index 00000000000..0a59d6e6aee --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/model_nginxcertificate.go @@ -0,0 +1,17 @@ +package nginxcertificate + +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 NginxCertificate struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *NginxCertificateProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxcertificate/model_nginxcertificateerrorresponsebody.go b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/model_nginxcertificateerrorresponsebody.go new file mode 100644 index 00000000000..2244c48f5dd --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/model_nginxcertificateerrorresponsebody.go @@ -0,0 +1,9 @@ +package nginxcertificate + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NginxCertificateErrorResponseBody struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxcertificate/model_nginxcertificateproperties.go b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/model_nginxcertificateproperties.go new file mode 100644 index 00000000000..41bbb8a097a --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/model_nginxcertificateproperties.go @@ -0,0 +1,33 @@ +package nginxcertificate + +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 NginxCertificateProperties struct { + CertificateError *NginxCertificateErrorResponseBody `json:"certificateError,omitempty"` + CertificateVirtualPath *string `json:"certificateVirtualPath,omitempty"` + KeyVaultSecretCreated *string `json:"keyVaultSecretCreated,omitempty"` + KeyVaultSecretId *string `json:"keyVaultSecretId,omitempty"` + KeyVaultSecretVersion *string `json:"keyVaultSecretVersion,omitempty"` + KeyVirtualPath *string `json:"keyVirtualPath,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + Sha1Thumbprint *string `json:"sha1Thumbprint,omitempty"` +} + +func (o *NginxCertificateProperties) GetKeyVaultSecretCreatedAsTime() (*time.Time, error) { + if o.KeyVaultSecretCreated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.KeyVaultSecretCreated, "2006-01-02T15:04:05Z07:00") +} + +func (o *NginxCertificateProperties) SetKeyVaultSecretCreatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.KeyVaultSecretCreated = &formatted +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxcertificate/predicates.go b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/predicates.go new file mode 100644 index 00000000000..b01a724d879 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/predicates.go @@ -0,0 +1,32 @@ +package nginxcertificate + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NginxCertificateOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p NginxCertificateOperationPredicate) Matches(input NginxCertificate) 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/nginx/2024-06-01-preview/nginxcertificate/version.go b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/version.go new file mode 100644 index 00000000000..a7cab5e10c6 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxcertificate/version.go @@ -0,0 +1,12 @@ +package nginxcertificate + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-06-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/nginxcertificate/%s", defaultApiVersion) +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/README.md b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/README.md new file mode 100644 index 00000000000..0258d9fb5dc --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-06-01-preview/nginxconfiguration` Documentation + +The `nginxconfiguration` SDK allows for interaction with the Azure Resource Manager Service `nginx` (API Version `2024-06-01-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/nginx/2024-06-01-preview/nginxconfiguration" +``` + + +### Client Initialization + +```go +client := nginxconfiguration.NewNginxConfigurationClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `NginxConfigurationClient.ConfigurationsCreateOrUpdate` + +```go +ctx := context.TODO() +id := nginxconfiguration.NewConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue", "configurationValue") + +payload := nginxconfiguration.NginxConfiguration{ + // ... +} + + +if err := client.ConfigurationsCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `NginxConfigurationClient.ConfigurationsDelete` + +```go +ctx := context.TODO() +id := nginxconfiguration.NewConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue", "configurationValue") + +if err := client.ConfigurationsDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `NginxConfigurationClient.ConfigurationsGet` + +```go +ctx := context.TODO() +id := nginxconfiguration.NewConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue", "configurationValue") + +read, err := client.ConfigurationsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NginxConfigurationClient.ConfigurationsList` + +```go +ctx := context.TODO() +id := nginxconfiguration.NewNginxDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue") + +// alternatively `client.ConfigurationsList(ctx, id)` can be used to do batched pagination +items, err := client.ConfigurationsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/client.go b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/client.go new file mode 100644 index 00000000000..d845625bb59 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/client.go @@ -0,0 +1,26 @@ +package nginxconfiguration + +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 NginxConfigurationClient struct { + Client *resourcemanager.Client +} + +func NewNginxConfigurationClientWithBaseURI(sdkApi sdkEnv.Api) (*NginxConfigurationClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "nginxconfiguration", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating NginxConfigurationClient: %+v", err) + } + + return &NginxConfigurationClient{ + Client: client, + }, nil +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/constants.go b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/constants.go new file mode 100644 index 00000000000..9abf4d96b6b --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/constants.go @@ -0,0 +1,72 @@ +package nginxconfiguration + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "notspecified": ProvisioningStateNotSpecified, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/id_configuration.go b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/id_configuration.go new file mode 100644 index 00000000000..f8a7f55611e --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/id_configuration.go @@ -0,0 +1,139 @@ +package nginxconfiguration + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ConfigurationId{}) +} + +var _ resourceids.ResourceId = &ConfigurationId{} + +// ConfigurationId is a struct representing the Resource ID for a Configuration +type ConfigurationId struct { + SubscriptionId string + ResourceGroupName string + NginxDeploymentName string + ConfigurationName string +} + +// NewConfigurationID returns a new ConfigurationId struct +func NewConfigurationID(subscriptionId string, resourceGroupName string, nginxDeploymentName string, configurationName string) ConfigurationId { + return ConfigurationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + NginxDeploymentName: nginxDeploymentName, + ConfigurationName: configurationName, + } +} + +// ParseConfigurationID parses 'input' into a ConfigurationId +func ParseConfigurationID(input string) (*ConfigurationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ConfigurationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ConfigurationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseConfigurationIDInsensitively parses 'input' case-insensitively into a ConfigurationId +// note: this method should only be used for API response data and not user input +func ParseConfigurationIDInsensitively(input string) (*ConfigurationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ConfigurationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ConfigurationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ConfigurationId) 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.NginxDeploymentName, ok = input.Parsed["nginxDeploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "nginxDeploymentName", input) + } + + if id.ConfigurationName, ok = input.Parsed["configurationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "configurationName", input) + } + + return nil +} + +// ValidateConfigurationID checks that 'input' can be parsed as a Configuration ID +func ValidateConfigurationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseConfigurationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Configuration ID +func (id ConfigurationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Nginx.NginxPlus/nginxDeployments/%s/configurations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.NginxDeploymentName, id.ConfigurationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Configuration ID +func (id ConfigurationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticNginxNginxPlus", "Nginx.NginxPlus", "Nginx.NginxPlus"), + resourceids.StaticSegment("staticNginxDeployments", "nginxDeployments", "nginxDeployments"), + resourceids.UserSpecifiedSegment("nginxDeploymentName", "nginxDeploymentValue"), + resourceids.StaticSegment("staticConfigurations", "configurations", "configurations"), + resourceids.UserSpecifiedSegment("configurationName", "configurationValue"), + } +} + +// String returns a human-readable description of this Configuration ID +func (id ConfigurationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Nginx Deployment Name: %q", id.NginxDeploymentName), + fmt.Sprintf("Configuration Name: %q", id.ConfigurationName), + } + return fmt.Sprintf("Configuration (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/id_configuration_test.go b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/id_configuration_test.go new file mode 100644 index 00000000000..f234c08f8e9 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/id_configuration_test.go @@ -0,0 +1,327 @@ +package nginxconfiguration + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ConfigurationId{} + +func TestNewConfigurationID(t *testing.T) { + id := NewConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue", "configurationValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.NginxDeploymentName != "nginxDeploymentValue" { + t.Fatalf("Expected %q but got %q for Segment 'NginxDeploymentName'", id.NginxDeploymentName, "nginxDeploymentValue") + } + + if id.ConfigurationName != "configurationValue" { + t.Fatalf("Expected %q but got %q for Segment 'ConfigurationName'", id.ConfigurationName, "configurationValue") + } +} + +func TestFormatConfigurationID(t *testing.T) { + actual := NewConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue", "configurationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/configurations/configurationValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseConfigurationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConfigurationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/configurations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/configurations/configurationValue", + Expected: &ConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NginxDeploymentName: "nginxDeploymentValue", + ConfigurationName: "configurationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/configurations/configurationValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConfigurationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NginxDeploymentName != v.Expected.NginxDeploymentName { + t.Fatalf("Expected %q but got %q for NginxDeploymentName", v.Expected.NginxDeploymentName, actual.NginxDeploymentName) + } + + if actual.ConfigurationName != v.Expected.ConfigurationName { + t.Fatalf("Expected %q but got %q for ConfigurationName", v.Expected.ConfigurationName, actual.ConfigurationName) + } + + } +} + +func TestParseConfigurationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConfigurationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs/nGiNxDePlOyMeNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs/nGiNxDePlOyMeNtS/nGiNxDePlOyMeNtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/configurations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs/nGiNxDePlOyMeNtS/nGiNxDePlOyMeNtVaLuE/cOnFiGuRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/configurations/configurationValue", + Expected: &ConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NginxDeploymentName: "nginxDeploymentValue", + ConfigurationName: "configurationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/configurations/configurationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs/nGiNxDePlOyMeNtS/nGiNxDePlOyMeNtVaLuE/cOnFiGuRaTiOnS/cOnFiGuRaTiOnVaLuE", + Expected: &ConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + NginxDeploymentName: "nGiNxDePlOyMeNtVaLuE", + ConfigurationName: "cOnFiGuRaTiOnVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs/nGiNxDePlOyMeNtS/nGiNxDePlOyMeNtVaLuE/cOnFiGuRaTiOnS/cOnFiGuRaTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConfigurationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NginxDeploymentName != v.Expected.NginxDeploymentName { + t.Fatalf("Expected %q but got %q for NginxDeploymentName", v.Expected.NginxDeploymentName, actual.NginxDeploymentName) + } + + if actual.ConfigurationName != v.Expected.ConfigurationName { + t.Fatalf("Expected %q but got %q for ConfigurationName", v.Expected.ConfigurationName, actual.ConfigurationName) + } + + } +} + +func TestSegmentsForConfigurationId(t *testing.T) { + segments := ConfigurationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ConfigurationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/id_nginxdeployment.go b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/id_nginxdeployment.go new file mode 100644 index 00000000000..68f2adda863 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/id_nginxdeployment.go @@ -0,0 +1,130 @@ +package nginxconfiguration + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&NginxDeploymentId{}) +} + +var _ resourceids.ResourceId = &NginxDeploymentId{} + +// NginxDeploymentId is a struct representing the Resource ID for a Nginx Deployment +type NginxDeploymentId struct { + SubscriptionId string + ResourceGroupName string + NginxDeploymentName string +} + +// NewNginxDeploymentID returns a new NginxDeploymentId struct +func NewNginxDeploymentID(subscriptionId string, resourceGroupName string, nginxDeploymentName string) NginxDeploymentId { + return NginxDeploymentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + NginxDeploymentName: nginxDeploymentName, + } +} + +// ParseNginxDeploymentID parses 'input' into a NginxDeploymentId +func ParseNginxDeploymentID(input string) (*NginxDeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&NginxDeploymentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NginxDeploymentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNginxDeploymentIDInsensitively parses 'input' case-insensitively into a NginxDeploymentId +// note: this method should only be used for API response data and not user input +func ParseNginxDeploymentIDInsensitively(input string) (*NginxDeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&NginxDeploymentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NginxDeploymentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NginxDeploymentId) 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.NginxDeploymentName, ok = input.Parsed["nginxDeploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "nginxDeploymentName", input) + } + + return nil +} + +// ValidateNginxDeploymentID checks that 'input' can be parsed as a Nginx Deployment ID +func ValidateNginxDeploymentID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseNginxDeploymentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Nginx Deployment ID +func (id NginxDeploymentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Nginx.NginxPlus/nginxDeployments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.NginxDeploymentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Nginx Deployment ID +func (id NginxDeploymentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticNginxNginxPlus", "Nginx.NginxPlus", "Nginx.NginxPlus"), + resourceids.StaticSegment("staticNginxDeployments", "nginxDeployments", "nginxDeployments"), + resourceids.UserSpecifiedSegment("nginxDeploymentName", "nginxDeploymentValue"), + } +} + +// String returns a human-readable description of this Nginx Deployment ID +func (id NginxDeploymentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Nginx Deployment Name: %q", id.NginxDeploymentName), + } + return fmt.Sprintf("Nginx Deployment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/id_nginxdeployment_test.go b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/id_nginxdeployment_test.go new file mode 100644 index 00000000000..f47b5a616f4 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/id_nginxdeployment_test.go @@ -0,0 +1,282 @@ +package nginxconfiguration + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &NginxDeploymentId{} + +func TestNewNginxDeploymentID(t *testing.T) { + id := NewNginxDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.NginxDeploymentName != "nginxDeploymentValue" { + t.Fatalf("Expected %q but got %q for Segment 'NginxDeploymentName'", id.NginxDeploymentName, "nginxDeploymentValue") + } +} + +func TestFormatNginxDeploymentID(t *testing.T) { + actual := NewNginxDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNginxDeploymentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NginxDeploymentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue", + Expected: &NginxDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NginxDeploymentName: "nginxDeploymentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNginxDeploymentID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NginxDeploymentName != v.Expected.NginxDeploymentName { + t.Fatalf("Expected %q but got %q for NginxDeploymentName", v.Expected.NginxDeploymentName, actual.NginxDeploymentName) + } + + } +} + +func TestParseNginxDeploymentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NginxDeploymentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs/nGiNxDePlOyMeNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue", + Expected: &NginxDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NginxDeploymentName: "nginxDeploymentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs/nGiNxDePlOyMeNtS/nGiNxDePlOyMeNtVaLuE", + Expected: &NginxDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + NginxDeploymentName: "nGiNxDePlOyMeNtVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs/nGiNxDePlOyMeNtS/nGiNxDePlOyMeNtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNginxDeploymentIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NginxDeploymentName != v.Expected.NginxDeploymentName { + t.Fatalf("Expected %q but got %q for NginxDeploymentName", v.Expected.NginxDeploymentName, actual.NginxDeploymentName) + } + + } +} + +func TestSegmentsForNginxDeploymentId(t *testing.T) { + segments := NginxDeploymentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NginxDeploymentId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/method_configurationscreateorupdate.go b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/method_configurationscreateorupdate.go new file mode 100644 index 00000000000..dea245223f0 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/method_configurationscreateorupdate.go @@ -0,0 +1,75 @@ +package nginxconfiguration + +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 ConfigurationsCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *NginxConfiguration +} + +// ConfigurationsCreateOrUpdate ... +func (c NginxConfigurationClient) ConfigurationsCreateOrUpdate(ctx context.Context, id ConfigurationId, input NginxConfiguration) (result ConfigurationsCreateOrUpdateOperationResponse, 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 +} + +// ConfigurationsCreateOrUpdateThenPoll performs ConfigurationsCreateOrUpdate then polls until it's completed +func (c NginxConfigurationClient) ConfigurationsCreateOrUpdateThenPoll(ctx context.Context, id ConfigurationId, input NginxConfiguration) error { + result, err := c.ConfigurationsCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ConfigurationsCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ConfigurationsCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/method_configurationsdelete.go b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/method_configurationsdelete.go new file mode 100644 index 00000000000..37e56e51da7 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/method_configurationsdelete.go @@ -0,0 +1,71 @@ +package nginxconfiguration + +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 ConfigurationsDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// ConfigurationsDelete ... +func (c NginxConfigurationClient) ConfigurationsDelete(ctx context.Context, id ConfigurationId) (result ConfigurationsDeleteOperationResponse, 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 +} + +// ConfigurationsDeleteThenPoll performs ConfigurationsDelete then polls until it's completed +func (c NginxConfigurationClient) ConfigurationsDeleteThenPoll(ctx context.Context, id ConfigurationId) error { + result, err := c.ConfigurationsDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing ConfigurationsDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ConfigurationsDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/method_configurationsget.go b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/method_configurationsget.go new file mode 100644 index 00000000000..fd35b6eb8f7 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/method_configurationsget.go @@ -0,0 +1,54 @@ +package nginxconfiguration + +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 ConfigurationsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *NginxConfiguration +} + +// ConfigurationsGet ... +func (c NginxConfigurationClient) ConfigurationsGet(ctx context.Context, id ConfigurationId) (result ConfigurationsGetOperationResponse, 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 NginxConfiguration + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/method_configurationslist.go b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/method_configurationslist.go new file mode 100644 index 00000000000..b450e93d029 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/method_configurationslist.go @@ -0,0 +1,105 @@ +package nginxconfiguration + +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 ConfigurationsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]NginxConfiguration +} + +type ConfigurationsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []NginxConfiguration +} + +type ConfigurationsListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ConfigurationsListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ConfigurationsList ... +func (c NginxConfigurationClient) ConfigurationsList(ctx context.Context, id NginxDeploymentId) (result ConfigurationsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ConfigurationsListCustomPager{}, + Path: fmt.Sprintf("%s/configurations", 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 *[]NginxConfiguration `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ConfigurationsListComplete retrieves all the results into a single object +func (c NginxConfigurationClient) ConfigurationsListComplete(ctx context.Context, id NginxDeploymentId) (ConfigurationsListCompleteResult, error) { + return c.ConfigurationsListCompleteMatchingPredicate(ctx, id, NginxConfigurationOperationPredicate{}) +} + +// ConfigurationsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c NginxConfigurationClient) ConfigurationsListCompleteMatchingPredicate(ctx context.Context, id NginxDeploymentId, predicate NginxConfigurationOperationPredicate) (result ConfigurationsListCompleteResult, err error) { + items := make([]NginxConfiguration, 0) + + resp, err := c.ConfigurationsList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ConfigurationsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/model_nginxconfiguration.go b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/model_nginxconfiguration.go new file mode 100644 index 00000000000..06645eebbba --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/model_nginxconfiguration.go @@ -0,0 +1,17 @@ +package nginxconfiguration + +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 NginxConfiguration struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *NginxConfigurationProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/model_nginxconfigurationfile.go b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/model_nginxconfigurationfile.go new file mode 100644 index 00000000000..127f7ff425a --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/model_nginxconfigurationfile.go @@ -0,0 +1,9 @@ +package nginxconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NginxConfigurationFile struct { + Content *string `json:"content,omitempty"` + VirtualPath *string `json:"virtualPath,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/model_nginxconfigurationpackage.go b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/model_nginxconfigurationpackage.go new file mode 100644 index 00000000000..b247778b539 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/model_nginxconfigurationpackage.go @@ -0,0 +1,9 @@ +package nginxconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NginxConfigurationPackage struct { + Data *string `json:"data,omitempty"` + ProtectedFiles *[]string `json:"protectedFiles,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/model_nginxconfigurationproperties.go b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/model_nginxconfigurationproperties.go new file mode 100644 index 00000000000..b68a006b58d --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/model_nginxconfigurationproperties.go @@ -0,0 +1,12 @@ +package nginxconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NginxConfigurationProperties struct { + Files *[]NginxConfigurationFile `json:"files,omitempty"` + Package *NginxConfigurationPackage `json:"package,omitempty"` + ProtectedFiles *[]NginxConfigurationFile `json:"protectedFiles,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + RootFile *string `json:"rootFile,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/predicates.go b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/predicates.go new file mode 100644 index 00000000000..0958a9d2b5d --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/predicates.go @@ -0,0 +1,32 @@ +package nginxconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NginxConfigurationOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p NginxConfigurationOperationPredicate) Matches(input NginxConfiguration) 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/nginx/2024-06-01-preview/nginxconfiguration/version.go b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/version.go new file mode 100644 index 00000000000..3fcb4bfbc88 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfiguration/version.go @@ -0,0 +1,12 @@ +package nginxconfiguration + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-06-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/nginxconfiguration/%s", defaultApiVersion) +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/README.md b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/README.md new file mode 100644 index 00000000000..959b80f7f26 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/README.md @@ -0,0 +1,41 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis` Documentation + +The `nginxconfigurationanalysis` SDK allows for interaction with the Azure Resource Manager Service `nginx` (API Version `2024-06-01-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/nginx/2024-06-01-preview/nginxconfigurationanalysis" +``` + + +### Client Initialization + +```go +client := nginxconfigurationanalysis.NewNginxConfigurationAnalysisClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `NginxConfigurationAnalysisClient.ConfigurationsAnalysis` + +```go +ctx := context.TODO() +id := nginxconfigurationanalysis.NewConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue", "configurationValue") + +payload := nginxconfigurationanalysis.AnalysisCreate{ + // ... +} + + +read, err := client.ConfigurationsAnalysis(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/nginx/2024-06-01-preview/nginxconfigurationanalysis/client.go b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/client.go new file mode 100644 index 00000000000..c35a72f8247 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/client.go @@ -0,0 +1,26 @@ +package nginxconfigurationanalysis + +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 NginxConfigurationAnalysisClient struct { + Client *resourcemanager.Client +} + +func NewNginxConfigurationAnalysisClientWithBaseURI(sdkApi sdkEnv.Api) (*NginxConfigurationAnalysisClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "nginxconfigurationanalysis", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating NginxConfigurationAnalysisClient: %+v", err) + } + + return &NginxConfigurationAnalysisClient{ + Client: client, + }, nil +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/id_configuration.go b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/id_configuration.go new file mode 100644 index 00000000000..7c08c8dfa9d --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/id_configuration.go @@ -0,0 +1,139 @@ +package nginxconfigurationanalysis + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ConfigurationId{}) +} + +var _ resourceids.ResourceId = &ConfigurationId{} + +// ConfigurationId is a struct representing the Resource ID for a Configuration +type ConfigurationId struct { + SubscriptionId string + ResourceGroupName string + NginxDeploymentName string + ConfigurationName string +} + +// NewConfigurationID returns a new ConfigurationId struct +func NewConfigurationID(subscriptionId string, resourceGroupName string, nginxDeploymentName string, configurationName string) ConfigurationId { + return ConfigurationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + NginxDeploymentName: nginxDeploymentName, + ConfigurationName: configurationName, + } +} + +// ParseConfigurationID parses 'input' into a ConfigurationId +func ParseConfigurationID(input string) (*ConfigurationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ConfigurationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ConfigurationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseConfigurationIDInsensitively parses 'input' case-insensitively into a ConfigurationId +// note: this method should only be used for API response data and not user input +func ParseConfigurationIDInsensitively(input string) (*ConfigurationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ConfigurationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ConfigurationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ConfigurationId) 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.NginxDeploymentName, ok = input.Parsed["nginxDeploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "nginxDeploymentName", input) + } + + if id.ConfigurationName, ok = input.Parsed["configurationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "configurationName", input) + } + + return nil +} + +// ValidateConfigurationID checks that 'input' can be parsed as a Configuration ID +func ValidateConfigurationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseConfigurationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Configuration ID +func (id ConfigurationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Nginx.NginxPlus/nginxDeployments/%s/configurations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.NginxDeploymentName, id.ConfigurationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Configuration ID +func (id ConfigurationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticNginxNginxPlus", "Nginx.NginxPlus", "Nginx.NginxPlus"), + resourceids.StaticSegment("staticNginxDeployments", "nginxDeployments", "nginxDeployments"), + resourceids.UserSpecifiedSegment("nginxDeploymentName", "nginxDeploymentValue"), + resourceids.StaticSegment("staticConfigurations", "configurations", "configurations"), + resourceids.UserSpecifiedSegment("configurationName", "configurationValue"), + } +} + +// String returns a human-readable description of this Configuration ID +func (id ConfigurationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Nginx Deployment Name: %q", id.NginxDeploymentName), + fmt.Sprintf("Configuration Name: %q", id.ConfigurationName), + } + return fmt.Sprintf("Configuration (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/id_configuration_test.go b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/id_configuration_test.go new file mode 100644 index 00000000000..9e453323577 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/id_configuration_test.go @@ -0,0 +1,327 @@ +package nginxconfigurationanalysis + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ConfigurationId{} + +func TestNewConfigurationID(t *testing.T) { + id := NewConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue", "configurationValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.NginxDeploymentName != "nginxDeploymentValue" { + t.Fatalf("Expected %q but got %q for Segment 'NginxDeploymentName'", id.NginxDeploymentName, "nginxDeploymentValue") + } + + if id.ConfigurationName != "configurationValue" { + t.Fatalf("Expected %q but got %q for Segment 'ConfigurationName'", id.ConfigurationName, "configurationValue") + } +} + +func TestFormatConfigurationID(t *testing.T) { + actual := NewConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue", "configurationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/configurations/configurationValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseConfigurationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConfigurationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/configurations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/configurations/configurationValue", + Expected: &ConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NginxDeploymentName: "nginxDeploymentValue", + ConfigurationName: "configurationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/configurations/configurationValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConfigurationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NginxDeploymentName != v.Expected.NginxDeploymentName { + t.Fatalf("Expected %q but got %q for NginxDeploymentName", v.Expected.NginxDeploymentName, actual.NginxDeploymentName) + } + + if actual.ConfigurationName != v.Expected.ConfigurationName { + t.Fatalf("Expected %q but got %q for ConfigurationName", v.Expected.ConfigurationName, actual.ConfigurationName) + } + + } +} + +func TestParseConfigurationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConfigurationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs/nGiNxDePlOyMeNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs/nGiNxDePlOyMeNtS/nGiNxDePlOyMeNtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/configurations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs/nGiNxDePlOyMeNtS/nGiNxDePlOyMeNtVaLuE/cOnFiGuRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/configurations/configurationValue", + Expected: &ConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NginxDeploymentName: "nginxDeploymentValue", + ConfigurationName: "configurationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/configurations/configurationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs/nGiNxDePlOyMeNtS/nGiNxDePlOyMeNtVaLuE/cOnFiGuRaTiOnS/cOnFiGuRaTiOnVaLuE", + Expected: &ConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + NginxDeploymentName: "nGiNxDePlOyMeNtVaLuE", + ConfigurationName: "cOnFiGuRaTiOnVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs/nGiNxDePlOyMeNtS/nGiNxDePlOyMeNtVaLuE/cOnFiGuRaTiOnS/cOnFiGuRaTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConfigurationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NginxDeploymentName != v.Expected.NginxDeploymentName { + t.Fatalf("Expected %q but got %q for NginxDeploymentName", v.Expected.NginxDeploymentName, actual.NginxDeploymentName) + } + + if actual.ConfigurationName != v.Expected.ConfigurationName { + t.Fatalf("Expected %q but got %q for ConfigurationName", v.Expected.ConfigurationName, actual.ConfigurationName) + } + + } +} + +func TestSegmentsForConfigurationId(t *testing.T) { + segments := ConfigurationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ConfigurationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/method_configurationsanalysis.go b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/method_configurationsanalysis.go new file mode 100644 index 00000000000..2c91a12e855 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/method_configurationsanalysis.go @@ -0,0 +1,59 @@ +package nginxconfigurationanalysis + +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 ConfigurationsAnalysisOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AnalysisResult +} + +// ConfigurationsAnalysis ... +func (c NginxConfigurationAnalysisClient) ConfigurationsAnalysis(ctx context.Context, id ConfigurationId, input AnalysisCreate) (result ConfigurationsAnalysisOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/analyze", 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 AnalysisResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/model_analysiscreate.go b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/model_analysiscreate.go new file mode 100644 index 00000000000..9bd340960df --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/model_analysiscreate.go @@ -0,0 +1,8 @@ +package nginxconfigurationanalysis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AnalysisCreate struct { + Config AnalysisCreateConfig `json:"config"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/model_analysiscreateconfig.go b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/model_analysiscreateconfig.go new file mode 100644 index 00000000000..5a84286132c --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/model_analysiscreateconfig.go @@ -0,0 +1,11 @@ +package nginxconfigurationanalysis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AnalysisCreateConfig struct { + Files *[]NginxConfigurationFile `json:"files,omitempty"` + Package *NginxConfigurationPackage `json:"package,omitempty"` + ProtectedFiles *[]NginxConfigurationFile `json:"protectedFiles,omitempty"` + RootFile *string `json:"rootFile,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/model_analysisdiagnostic.go b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/model_analysisdiagnostic.go new file mode 100644 index 00000000000..e4f1e75b97d --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/model_analysisdiagnostic.go @@ -0,0 +1,14 @@ +package nginxconfigurationanalysis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AnalysisDiagnostic struct { + Description string `json:"description"` + Directive string `json:"directive"` + File string `json:"file"` + Id *string `json:"id,omitempty"` + Line float64 `json:"line"` + Message string `json:"message"` + Rule string `json:"rule"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/model_analysisresult.go b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/model_analysisresult.go new file mode 100644 index 00000000000..f84e0071ea6 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/model_analysisresult.go @@ -0,0 +1,9 @@ +package nginxconfigurationanalysis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AnalysisResult struct { + Data *AnalysisResultData `json:"data,omitempty"` + Status string `json:"status"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/model_analysisresultdata.go b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/model_analysisresultdata.go new file mode 100644 index 00000000000..38119ba3240 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/model_analysisresultdata.go @@ -0,0 +1,8 @@ +package nginxconfigurationanalysis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AnalysisResultData struct { + Errors *[]AnalysisDiagnostic `json:"errors,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/model_nginxconfigurationfile.go b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/model_nginxconfigurationfile.go new file mode 100644 index 00000000000..1a735e79e48 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/model_nginxconfigurationfile.go @@ -0,0 +1,9 @@ +package nginxconfigurationanalysis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NginxConfigurationFile struct { + Content *string `json:"content,omitempty"` + VirtualPath *string `json:"virtualPath,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/model_nginxconfigurationpackage.go b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/model_nginxconfigurationpackage.go new file mode 100644 index 00000000000..0aa2af797f0 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/model_nginxconfigurationpackage.go @@ -0,0 +1,9 @@ +package nginxconfigurationanalysis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NginxConfigurationPackage struct { + Data *string `json:"data,omitempty"` + ProtectedFiles *[]string `json:"protectedFiles,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/version.go b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/version.go new file mode 100644 index 00000000000..48bdd2a99c3 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxconfigurationanalysis/version.go @@ -0,0 +1,12 @@ +package nginxconfigurationanalysis + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-06-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/nginxconfigurationanalysis/%s", defaultApiVersion) +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/README.md b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/README.md new file mode 100644 index 00000000000..41cf55ca837 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/README.md @@ -0,0 +1,117 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-06-01-preview/nginxdeployment` Documentation + +The `nginxdeployment` SDK allows for interaction with the Azure Resource Manager Service `nginx` (API Version `2024-06-01-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/nginx/2024-06-01-preview/nginxdeployment" +``` + + +### Client Initialization + +```go +client := nginxdeployment.NewNginxDeploymentClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `NginxDeploymentClient.DeploymentsCreateOrUpdate` + +```go +ctx := context.TODO() +id := nginxdeployment.NewNginxDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue") + +payload := nginxdeployment.NginxDeployment{ + // ... +} + + +if err := client.DeploymentsCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `NginxDeploymentClient.DeploymentsDelete` + +```go +ctx := context.TODO() +id := nginxdeployment.NewNginxDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue") + +if err := client.DeploymentsDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `NginxDeploymentClient.DeploymentsGet` + +```go +ctx := context.TODO() +id := nginxdeployment.NewNginxDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue") + +read, err := client.DeploymentsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NginxDeploymentClient.DeploymentsList` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.DeploymentsList(ctx, id)` can be used to do batched pagination +items, err := client.DeploymentsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `NginxDeploymentClient.DeploymentsListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.DeploymentsListByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.DeploymentsListByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `NginxDeploymentClient.DeploymentsUpdate` + +```go +ctx := context.TODO() +id := nginxdeployment.NewNginxDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue") + +payload := nginxdeployment.NginxDeploymentUpdateParameters{ + // ... +} + + +if err := client.DeploymentsUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/client.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/client.go new file mode 100644 index 00000000000..7f5e031b02e --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/client.go @@ -0,0 +1,26 @@ +package nginxdeployment + +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 NginxDeploymentClient struct { + Client *resourcemanager.Client +} + +func NewNginxDeploymentClientWithBaseURI(sdkApi sdkEnv.Api) (*NginxDeploymentClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "nginxdeployment", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating NginxDeploymentClient: %+v", err) + } + + return &NginxDeploymentClient{ + Client: client, + }, nil +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/constants.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/constants.go new file mode 100644 index 00000000000..08865eb91a2 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/constants.go @@ -0,0 +1,154 @@ +package nginxdeployment + +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 ActivationState string + +const ( + ActivationStateDisabled ActivationState = "Disabled" + ActivationStateEnabled ActivationState = "Enabled" +) + +func PossibleValuesForActivationState() []string { + return []string{ + string(ActivationStateDisabled), + string(ActivationStateEnabled), + } +} + +func (s *ActivationState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseActivationState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseActivationState(input string) (*ActivationState, error) { + vals := map[string]ActivationState{ + "disabled": ActivationStateDisabled, + "enabled": ActivationStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ActivationState(input) + return &out, nil +} + +type NginxPrivateIPAllocationMethod string + +const ( + NginxPrivateIPAllocationMethodDynamic NginxPrivateIPAllocationMethod = "Dynamic" + NginxPrivateIPAllocationMethodStatic NginxPrivateIPAllocationMethod = "Static" +) + +func PossibleValuesForNginxPrivateIPAllocationMethod() []string { + return []string{ + string(NginxPrivateIPAllocationMethodDynamic), + string(NginxPrivateIPAllocationMethodStatic), + } +} + +func (s *NginxPrivateIPAllocationMethod) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseNginxPrivateIPAllocationMethod(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseNginxPrivateIPAllocationMethod(input string) (*NginxPrivateIPAllocationMethod, error) { + vals := map[string]NginxPrivateIPAllocationMethod{ + "dynamic": NginxPrivateIPAllocationMethodDynamic, + "static": NginxPrivateIPAllocationMethodStatic, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NginxPrivateIPAllocationMethod(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "notspecified": ProvisioningStateNotSpecified, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/id_nginxdeployment.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/id_nginxdeployment.go new file mode 100644 index 00000000000..dd965d354cf --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/id_nginxdeployment.go @@ -0,0 +1,130 @@ +package nginxdeployment + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&NginxDeploymentId{}) +} + +var _ resourceids.ResourceId = &NginxDeploymentId{} + +// NginxDeploymentId is a struct representing the Resource ID for a Nginx Deployment +type NginxDeploymentId struct { + SubscriptionId string + ResourceGroupName string + NginxDeploymentName string +} + +// NewNginxDeploymentID returns a new NginxDeploymentId struct +func NewNginxDeploymentID(subscriptionId string, resourceGroupName string, nginxDeploymentName string) NginxDeploymentId { + return NginxDeploymentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + NginxDeploymentName: nginxDeploymentName, + } +} + +// ParseNginxDeploymentID parses 'input' into a NginxDeploymentId +func ParseNginxDeploymentID(input string) (*NginxDeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&NginxDeploymentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NginxDeploymentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNginxDeploymentIDInsensitively parses 'input' case-insensitively into a NginxDeploymentId +// note: this method should only be used for API response data and not user input +func ParseNginxDeploymentIDInsensitively(input string) (*NginxDeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&NginxDeploymentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NginxDeploymentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NginxDeploymentId) 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.NginxDeploymentName, ok = input.Parsed["nginxDeploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "nginxDeploymentName", input) + } + + return nil +} + +// ValidateNginxDeploymentID checks that 'input' can be parsed as a Nginx Deployment ID +func ValidateNginxDeploymentID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseNginxDeploymentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Nginx Deployment ID +func (id NginxDeploymentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Nginx.NginxPlus/nginxDeployments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.NginxDeploymentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Nginx Deployment ID +func (id NginxDeploymentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticNginxNginxPlus", "Nginx.NginxPlus", "Nginx.NginxPlus"), + resourceids.StaticSegment("staticNginxDeployments", "nginxDeployments", "nginxDeployments"), + resourceids.UserSpecifiedSegment("nginxDeploymentName", "nginxDeploymentValue"), + } +} + +// String returns a human-readable description of this Nginx Deployment ID +func (id NginxDeploymentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Nginx Deployment Name: %q", id.NginxDeploymentName), + } + return fmt.Sprintf("Nginx Deployment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/id_nginxdeployment_test.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/id_nginxdeployment_test.go new file mode 100644 index 00000000000..25fcab0649a --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/id_nginxdeployment_test.go @@ -0,0 +1,282 @@ +package nginxdeployment + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &NginxDeploymentId{} + +func TestNewNginxDeploymentID(t *testing.T) { + id := NewNginxDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.NginxDeploymentName != "nginxDeploymentValue" { + t.Fatalf("Expected %q but got %q for Segment 'NginxDeploymentName'", id.NginxDeploymentName, "nginxDeploymentValue") + } +} + +func TestFormatNginxDeploymentID(t *testing.T) { + actual := NewNginxDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "nginxDeploymentValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNginxDeploymentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NginxDeploymentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue", + Expected: &NginxDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NginxDeploymentName: "nginxDeploymentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNginxDeploymentID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NginxDeploymentName != v.Expected.NginxDeploymentName { + t.Fatalf("Expected %q but got %q for NginxDeploymentName", v.Expected.NginxDeploymentName, actual.NginxDeploymentName) + } + + } +} + +func TestParseNginxDeploymentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NginxDeploymentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs/nGiNxDePlOyMeNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue", + Expected: &NginxDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NginxDeploymentName: "nginxDeploymentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Nginx.NginxPlus/nginxDeployments/nginxDeploymentValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs/nGiNxDePlOyMeNtS/nGiNxDePlOyMeNtVaLuE", + Expected: &NginxDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + NginxDeploymentName: "nGiNxDePlOyMeNtVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/nGiNx.nGiNxPlUs/nGiNxDePlOyMeNtS/nGiNxDePlOyMeNtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNginxDeploymentIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.NginxDeploymentName != v.Expected.NginxDeploymentName { + t.Fatalf("Expected %q but got %q for NginxDeploymentName", v.Expected.NginxDeploymentName, actual.NginxDeploymentName) + } + + } +} + +func TestSegmentsForNginxDeploymentId(t *testing.T) { + segments := NginxDeploymentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NginxDeploymentId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/method_deploymentscreateorupdate.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/method_deploymentscreateorupdate.go new file mode 100644 index 00000000000..e4c9f1cba7b --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/method_deploymentscreateorupdate.go @@ -0,0 +1,75 @@ +package nginxdeployment + +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 DeploymentsCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *NginxDeployment +} + +// DeploymentsCreateOrUpdate ... +func (c NginxDeploymentClient) DeploymentsCreateOrUpdate(ctx context.Context, id NginxDeploymentId, input NginxDeployment) (result DeploymentsCreateOrUpdateOperationResponse, 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 +} + +// DeploymentsCreateOrUpdateThenPoll performs DeploymentsCreateOrUpdate then polls until it's completed +func (c NginxDeploymentClient) DeploymentsCreateOrUpdateThenPoll(ctx context.Context, id NginxDeploymentId, input NginxDeployment) error { + result, err := c.DeploymentsCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing DeploymentsCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DeploymentsCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/method_deploymentsdelete.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/method_deploymentsdelete.go new file mode 100644 index 00000000000..062f299f4a4 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/method_deploymentsdelete.go @@ -0,0 +1,71 @@ +package nginxdeployment + +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 DeploymentsDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DeploymentsDelete ... +func (c NginxDeploymentClient) DeploymentsDelete(ctx context.Context, id NginxDeploymentId) (result DeploymentsDeleteOperationResponse, 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 +} + +// DeploymentsDeleteThenPoll performs DeploymentsDelete then polls until it's completed +func (c NginxDeploymentClient) DeploymentsDeleteThenPoll(ctx context.Context, id NginxDeploymentId) error { + result, err := c.DeploymentsDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing DeploymentsDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DeploymentsDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/method_deploymentsget.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/method_deploymentsget.go new file mode 100644 index 00000000000..51818e9df34 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/method_deploymentsget.go @@ -0,0 +1,54 @@ +package nginxdeployment + +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 DeploymentsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *NginxDeployment +} + +// DeploymentsGet ... +func (c NginxDeploymentClient) DeploymentsGet(ctx context.Context, id NginxDeploymentId) (result DeploymentsGetOperationResponse, 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 NginxDeployment + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/method_deploymentslist.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/method_deploymentslist.go new file mode 100644 index 00000000000..f9a1c4b11c4 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/method_deploymentslist.go @@ -0,0 +1,106 @@ +package nginxdeployment + +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 DeploymentsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]NginxDeployment +} + +type DeploymentsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []NginxDeployment +} + +type DeploymentsListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *DeploymentsListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// DeploymentsList ... +func (c NginxDeploymentClient) DeploymentsList(ctx context.Context, id commonids.SubscriptionId) (result DeploymentsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &DeploymentsListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Nginx.NginxPlus/nginxDeployments", 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 *[]NginxDeployment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// DeploymentsListComplete retrieves all the results into a single object +func (c NginxDeploymentClient) DeploymentsListComplete(ctx context.Context, id commonids.SubscriptionId) (DeploymentsListCompleteResult, error) { + return c.DeploymentsListCompleteMatchingPredicate(ctx, id, NginxDeploymentOperationPredicate{}) +} + +// DeploymentsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c NginxDeploymentClient) DeploymentsListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate NginxDeploymentOperationPredicate) (result DeploymentsListCompleteResult, err error) { + items := make([]NginxDeployment, 0) + + resp, err := c.DeploymentsList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = DeploymentsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/method_deploymentslistbyresourcegroup.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/method_deploymentslistbyresourcegroup.go new file mode 100644 index 00000000000..3ac1cec05f7 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/method_deploymentslistbyresourcegroup.go @@ -0,0 +1,106 @@ +package nginxdeployment + +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 DeploymentsListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]NginxDeployment +} + +type DeploymentsListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []NginxDeployment +} + +type DeploymentsListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *DeploymentsListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// DeploymentsListByResourceGroup ... +func (c NginxDeploymentClient) DeploymentsListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result DeploymentsListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &DeploymentsListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Nginx.NginxPlus/nginxDeployments", 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 *[]NginxDeployment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// DeploymentsListByResourceGroupComplete retrieves all the results into a single object +func (c NginxDeploymentClient) DeploymentsListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (DeploymentsListByResourceGroupCompleteResult, error) { + return c.DeploymentsListByResourceGroupCompleteMatchingPredicate(ctx, id, NginxDeploymentOperationPredicate{}) +} + +// DeploymentsListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c NginxDeploymentClient) DeploymentsListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate NginxDeploymentOperationPredicate) (result DeploymentsListByResourceGroupCompleteResult, err error) { + items := make([]NginxDeployment, 0) + + resp, err := c.DeploymentsListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = DeploymentsListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/method_deploymentsupdate.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/method_deploymentsupdate.go new file mode 100644 index 00000000000..d6ab0244f52 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/method_deploymentsupdate.go @@ -0,0 +1,75 @@ +package nginxdeployment + +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 DeploymentsUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *NginxDeployment +} + +// DeploymentsUpdate ... +func (c NginxDeploymentClient) DeploymentsUpdate(ctx context.Context, id NginxDeploymentId, input NginxDeploymentUpdateParameters) (result DeploymentsUpdateOperationResponse, 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 +} + +// DeploymentsUpdateThenPoll performs DeploymentsUpdate then polls until it's completed +func (c NginxDeploymentClient) DeploymentsUpdateThenPoll(ctx context.Context, id NginxDeploymentId, input NginxDeploymentUpdateParameters) error { + result, err := c.DeploymentsUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing DeploymentsUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DeploymentsUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_autoupgradeprofile.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_autoupgradeprofile.go new file mode 100644 index 00000000000..2061898d495 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_autoupgradeprofile.go @@ -0,0 +1,8 @@ +package nginxdeployment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AutoUpgradeProfile struct { + UpgradeChannel string `json:"upgradeChannel"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeployment.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeployment.go new file mode 100644 index 00000000000..25453bf6d88 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeployment.go @@ -0,0 +1,21 @@ +package nginxdeployment + +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 NginxDeployment struct { + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *NginxDeploymentProperties `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/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeploymentproperties.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeploymentproperties.go new file mode 100644 index 00000000000..c89192b3324 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeploymentproperties.go @@ -0,0 +1,18 @@ +package nginxdeployment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NginxDeploymentProperties struct { + AutoUpgradeProfile *AutoUpgradeProfile `json:"autoUpgradeProfile,omitempty"` + EnableDiagnosticsSupport *bool `json:"enableDiagnosticsSupport,omitempty"` + IPAddress *string `json:"ipAddress,omitempty"` + Logging *NginxLogging `json:"logging,omitempty"` + ManagedResourceGroup *string `json:"managedResourceGroup,omitempty"` + NetworkProfile *NginxNetworkProfile `json:"networkProfile,omitempty"` + NginxAppProtect *NginxDeploymentPropertiesNginxAppProtect `json:"nginxAppProtect,omitempty"` + NginxVersion *string `json:"nginxVersion,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + ScalingProperties *NginxDeploymentScalingProperties `json:"scalingProperties,omitempty"` + UserProfile *NginxDeploymentUserProfile `json:"userProfile,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeploymentpropertiesnginxappprotect.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeploymentpropertiesnginxappprotect.go new file mode 100644 index 00000000000..326054a7d1e --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeploymentpropertiesnginxappprotect.go @@ -0,0 +1,9 @@ +package nginxdeployment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NginxDeploymentPropertiesNginxAppProtect struct { + WebApplicationFirewallSettings WebApplicationFirewallSettings `json:"webApplicationFirewallSettings"` + WebApplicationFirewallStatus *WebApplicationFirewallStatus `json:"webApplicationFirewallStatus,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeploymentscalingproperties.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeploymentscalingproperties.go new file mode 100644 index 00000000000..7142527f38a --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeploymentscalingproperties.go @@ -0,0 +1,9 @@ +package nginxdeployment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NginxDeploymentScalingProperties struct { + AutoScaleSettings *NginxDeploymentScalingPropertiesAutoScaleSettings `json:"autoScaleSettings,omitempty"` + Capacity *int64 `json:"capacity,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeploymentscalingpropertiesautoscalesettings.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeploymentscalingpropertiesautoscalesettings.go new file mode 100644 index 00000000000..28951659cae --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeploymentscalingpropertiesautoscalesettings.go @@ -0,0 +1,8 @@ +package nginxdeployment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NginxDeploymentScalingPropertiesAutoScaleSettings struct { + Profiles []ScaleProfile `json:"profiles"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeploymentupdateparameters.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeploymentupdateparameters.go new file mode 100644 index 00000000000..00b1615d7e0 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeploymentupdateparameters.go @@ -0,0 +1,16 @@ +package nginxdeployment + +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 NginxDeploymentUpdateParameters struct { + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Location *string `json:"location,omitempty"` + Properties *NginxDeploymentUpdateProperties `json:"properties,omitempty"` + Sku *ResourceSku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeploymentupdateproperties.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeploymentupdateproperties.go new file mode 100644 index 00000000000..837727acbc8 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeploymentupdateproperties.go @@ -0,0 +1,13 @@ +package nginxdeployment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NginxDeploymentUpdateProperties struct { + AutoUpgradeProfile *AutoUpgradeProfile `json:"autoUpgradeProfile,omitempty"` + EnableDiagnosticsSupport *bool `json:"enableDiagnosticsSupport,omitempty"` + Logging *NginxLogging `json:"logging,omitempty"` + NginxAppProtect *NginxDeploymentUpdatePropertiesNginxAppProtect `json:"nginxAppProtect,omitempty"` + ScalingProperties *NginxDeploymentScalingProperties `json:"scalingProperties,omitempty"` + UserProfile *NginxDeploymentUserProfile `json:"userProfile,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeploymentupdatepropertiesnginxappprotect.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeploymentupdatepropertiesnginxappprotect.go new file mode 100644 index 00000000000..1346c7a9fa9 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeploymentupdatepropertiesnginxappprotect.go @@ -0,0 +1,8 @@ +package nginxdeployment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NginxDeploymentUpdatePropertiesNginxAppProtect struct { + WebApplicationFirewallSettings *WebApplicationFirewallSettings `json:"webApplicationFirewallSettings,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeploymentuserprofile.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeploymentuserprofile.go new file mode 100644 index 00000000000..153bfb0e2e1 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxdeploymentuserprofile.go @@ -0,0 +1,8 @@ +package nginxdeployment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NginxDeploymentUserProfile struct { + PreferredEmail *string `json:"preferredEmail,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxfrontendipconfiguration.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxfrontendipconfiguration.go new file mode 100644 index 00000000000..e084038d690 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxfrontendipconfiguration.go @@ -0,0 +1,9 @@ +package nginxdeployment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NginxFrontendIPConfiguration struct { + PrivateIPAddresses *[]NginxPrivateIPAddress `json:"privateIPAddresses,omitempty"` + PublicIPAddresses *[]NginxPublicIPAddress `json:"publicIPAddresses,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxlogging.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxlogging.go new file mode 100644 index 00000000000..c5c8ff18d05 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxlogging.go @@ -0,0 +1,8 @@ +package nginxdeployment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NginxLogging struct { + StorageAccount *NginxStorageAccount `json:"storageAccount,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxnetworkinterfaceconfiguration.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxnetworkinterfaceconfiguration.go new file mode 100644 index 00000000000..b101806aebb --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxnetworkinterfaceconfiguration.go @@ -0,0 +1,8 @@ +package nginxdeployment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NginxNetworkInterfaceConfiguration struct { + SubnetId *string `json:"subnetId,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxnetworkprofile.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxnetworkprofile.go new file mode 100644 index 00000000000..26ded847b53 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxnetworkprofile.go @@ -0,0 +1,9 @@ +package nginxdeployment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NginxNetworkProfile struct { + FrontEndIPConfiguration *NginxFrontendIPConfiguration `json:"frontEndIPConfiguration,omitempty"` + NetworkInterfaceConfiguration *NginxNetworkInterfaceConfiguration `json:"networkInterfaceConfiguration,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxprivateipaddress.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxprivateipaddress.go new file mode 100644 index 00000000000..9bce7dba730 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxprivateipaddress.go @@ -0,0 +1,10 @@ +package nginxdeployment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NginxPrivateIPAddress struct { + PrivateIPAddress *string `json:"privateIPAddress,omitempty"` + PrivateIPAllocationMethod *NginxPrivateIPAllocationMethod `json:"privateIPAllocationMethod,omitempty"` + SubnetId *string `json:"subnetId,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxpublicipaddress.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxpublicipaddress.go new file mode 100644 index 00000000000..05e8036a6e4 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxpublicipaddress.go @@ -0,0 +1,8 @@ +package nginxdeployment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NginxPublicIPAddress struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxstorageaccount.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxstorageaccount.go new file mode 100644 index 00000000000..f53382105bf --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_nginxstorageaccount.go @@ -0,0 +1,9 @@ +package nginxdeployment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NginxStorageAccount struct { + AccountName *string `json:"accountName,omitempty"` + ContainerName *string `json:"containerName,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_resourcesku.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_resourcesku.go new file mode 100644 index 00000000000..85a9b9b55da --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_resourcesku.go @@ -0,0 +1,8 @@ +package nginxdeployment + +// 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 string `json:"name"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_scaleprofile.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_scaleprofile.go new file mode 100644 index 00000000000..35f11b10aa5 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_scaleprofile.go @@ -0,0 +1,9 @@ +package nginxdeployment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScaleProfile struct { + Capacity ScaleProfileCapacity `json:"capacity"` + Name string `json:"name"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_scaleprofilecapacity.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_scaleprofilecapacity.go new file mode 100644 index 00000000000..a1fd2137891 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_scaleprofilecapacity.go @@ -0,0 +1,9 @@ +package nginxdeployment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScaleProfileCapacity struct { + Max int64 `json:"max"` + Min int64 `json:"min"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_webapplicationfirewallcomponentversions.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_webapplicationfirewallcomponentversions.go new file mode 100644 index 00000000000..b3a49fdab79 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_webapplicationfirewallcomponentversions.go @@ -0,0 +1,9 @@ +package nginxdeployment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WebApplicationFirewallComponentVersions struct { + WafEngineVersion string `json:"wafEngineVersion"` + WafNginxVersion string `json:"wafNginxVersion"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_webapplicationfirewallpackage.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_webapplicationfirewallpackage.go new file mode 100644 index 00000000000..d86fe0ab588 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_webapplicationfirewallpackage.go @@ -0,0 +1,24 @@ +package nginxdeployment + +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 WebApplicationFirewallPackage struct { + RevisionDatetime string `json:"revisionDatetime"` + Version string `json:"version"` +} + +func (o *WebApplicationFirewallPackage) GetRevisionDatetimeAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.RevisionDatetime, "2006-01-02T15:04:05Z07:00") +} + +func (o *WebApplicationFirewallPackage) SetRevisionDatetimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RevisionDatetime = formatted +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_webapplicationfirewallsettings.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_webapplicationfirewallsettings.go new file mode 100644 index 00000000000..5fef9fad979 --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_webapplicationfirewallsettings.go @@ -0,0 +1,8 @@ +package nginxdeployment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WebApplicationFirewallSettings struct { + ActivationState *ActivationState `json:"activationState,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_webapplicationfirewallstatus.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_webapplicationfirewallstatus.go new file mode 100644 index 00000000000..923f4f159db --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/model_webapplicationfirewallstatus.go @@ -0,0 +1,11 @@ +package nginxdeployment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WebApplicationFirewallStatus struct { + AttackSignaturesPackage *WebApplicationFirewallPackage `json:"attackSignaturesPackage,omitempty"` + BotSignaturesPackage *WebApplicationFirewallPackage `json:"botSignaturesPackage,omitempty"` + ComponentVersions *WebApplicationFirewallComponentVersions `json:"componentVersions,omitempty"` + ThreatCampaignsPackage *WebApplicationFirewallPackage `json:"threatCampaignsPackage,omitempty"` +} diff --git a/resource-manager/nginx/2024-06-01-preview/nginxdeployment/predicates.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/predicates.go new file mode 100644 index 00000000000..d1754320d3a --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/predicates.go @@ -0,0 +1,32 @@ +package nginxdeployment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NginxDeploymentOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p NginxDeploymentOperationPredicate) Matches(input NginxDeployment) 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/nginx/2024-06-01-preview/nginxdeployment/version.go b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/version.go new file mode 100644 index 00000000000..821a4a635ef --- /dev/null +++ b/resource-manager/nginx/2024-06-01-preview/nginxdeployment/version.go @@ -0,0 +1,12 @@ +package nginxdeployment + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-06-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/nginxdeployment/%s", defaultApiVersion) +}