From 9ab4b4d9db07ec90955fb50a64c860da54ab7c90 Mon Sep 17 00:00:00 2001 From: hc-github-team-tf-azure <> Date: Thu, 18 Jan 2024 17:37:04 +0000 Subject: [PATCH] Updating based on 6c5cc95c6 --- .../2023-04-15-preview/capabilities/README.md | 8 +- .../capabilities/id_scopedcapability.go | 124 -------- .../capabilities/id_scopedcapability_test.go | 267 ------------------ .../capabilities/id_scopedtarget.go | 115 -------- .../capabilities/id_scopedtarget_test.go | 222 --------------- .../capabilities/method_createorupdate.go | 3 +- .../capabilities/method_delete.go | 3 +- .../capabilities/method_get.go | 3 +- .../capabilities/method_list.go | 7 +- .../2023-04-15-preview/targets/README.md | 6 +- .../targets/id_scopedtarget.go | 115 -------- .../targets/id_scopedtarget_test.go | 222 --------------- .../targets/method_createorupdate.go | 3 +- .../targets/method_delete.go | 3 +- .../2023-04-15-preview/targets/method_get.go | 3 +- .../2023-11-01/capabilities/README.md | 8 +- .../capabilities/id_scopedcapability.go | 124 -------- .../capabilities/id_scopedcapability_test.go | 267 ------------------ .../capabilities/id_scopedtarget.go | 115 -------- .../capabilities/id_scopedtarget_test.go | 222 --------------- .../capabilities/method_createorupdate.go | 3 +- .../2023-11-01/capabilities/method_delete.go | 3 +- .../2023-11-01/capabilities/method_get.go | 3 +- .../2023-11-01/capabilities/method_list.go | 7 +- .../chaosstudio/2023-11-01/targets/README.md | 6 +- .../2023-11-01/targets/id_scopedtarget.go | 115 -------- .../targets/id_scopedtarget_test.go | 222 --------------- .../targets/method_createorupdate.go | 3 +- .../2023-11-01/targets/method_delete.go | 3 +- .../2023-11-01/targets/method_get.go | 3 +- .../2024-01-01/capabilities/README.md | 8 +- .../capabilities/id_scopedcapability.go | 124 -------- .../capabilities/id_scopedcapability_test.go | 267 ------------------ .../capabilities/id_scopedtarget.go | 115 -------- .../capabilities/id_scopedtarget_test.go | 222 --------------- .../capabilities/method_createorupdate.go | 3 +- .../2024-01-01/capabilities/method_delete.go | 3 +- .../2024-01-01/capabilities/method_get.go | 3 +- .../2024-01-01/capabilities/method_list.go | 7 +- .../chaosstudio/2024-01-01/targets/README.md | 6 +- .../2024-01-01/targets/id_scopedtarget.go | 115 -------- .../targets/id_scopedtarget_test.go | 222 --------------- .../targets/method_createorupdate.go | 3 +- .../2024-01-01/targets/method_delete.go | 3 +- .../2024-01-01/targets/method_get.go | 3 +- 45 files changed, 69 insertions(+), 3243 deletions(-) delete mode 100644 resource-manager/chaosstudio/2023-04-15-preview/capabilities/id_scopedcapability.go delete mode 100644 resource-manager/chaosstudio/2023-04-15-preview/capabilities/id_scopedcapability_test.go delete mode 100644 resource-manager/chaosstudio/2023-04-15-preview/capabilities/id_scopedtarget.go delete mode 100644 resource-manager/chaosstudio/2023-04-15-preview/capabilities/id_scopedtarget_test.go delete mode 100644 resource-manager/chaosstudio/2023-04-15-preview/targets/id_scopedtarget.go delete mode 100644 resource-manager/chaosstudio/2023-04-15-preview/targets/id_scopedtarget_test.go delete mode 100644 resource-manager/chaosstudio/2023-11-01/capabilities/id_scopedcapability.go delete mode 100644 resource-manager/chaosstudio/2023-11-01/capabilities/id_scopedcapability_test.go delete mode 100644 resource-manager/chaosstudio/2023-11-01/capabilities/id_scopedtarget.go delete mode 100644 resource-manager/chaosstudio/2023-11-01/capabilities/id_scopedtarget_test.go delete mode 100644 resource-manager/chaosstudio/2023-11-01/targets/id_scopedtarget.go delete mode 100644 resource-manager/chaosstudio/2023-11-01/targets/id_scopedtarget_test.go delete mode 100644 resource-manager/chaosstudio/2024-01-01/capabilities/id_scopedcapability.go delete mode 100644 resource-manager/chaosstudio/2024-01-01/capabilities/id_scopedcapability_test.go delete mode 100644 resource-manager/chaosstudio/2024-01-01/capabilities/id_scopedtarget.go delete mode 100644 resource-manager/chaosstudio/2024-01-01/capabilities/id_scopedtarget_test.go delete mode 100644 resource-manager/chaosstudio/2024-01-01/targets/id_scopedtarget.go delete mode 100644 resource-manager/chaosstudio/2024-01-01/targets/id_scopedtarget_test.go diff --git a/resource-manager/chaosstudio/2023-04-15-preview/capabilities/README.md b/resource-manager/chaosstudio/2023-04-15-preview/capabilities/README.md index 987d8bb7e40..8de291d8a1a 100644 --- a/resource-manager/chaosstudio/2023-04-15-preview/capabilities/README.md +++ b/resource-manager/chaosstudio/2023-04-15-preview/capabilities/README.md @@ -40,7 +40,7 @@ if model := read.Model; model != nil { ```go ctx := context.TODO() -id := capabilities.NewScopedCapabilityID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue", "capabilityValue") +id := capabilities.NewChaosStudioCapabilityID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue", "capabilityValue") payload := capabilities.Capability{ // ... @@ -61,7 +61,7 @@ if model := read.Model; model != nil { ```go ctx := context.TODO() -id := capabilities.NewScopedCapabilityID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue", "capabilityValue") +id := capabilities.NewChaosStudioCapabilityID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue", "capabilityValue") read, err := client.Delete(ctx, id) if err != nil { @@ -77,7 +77,7 @@ if model := read.Model; model != nil { ```go ctx := context.TODO() -id := capabilities.NewScopedCapabilityID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue", "capabilityValue") +id := capabilities.NewChaosStudioCapabilityID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue", "capabilityValue") read, err := client.Get(ctx, id) if err != nil { @@ -93,7 +93,7 @@ if model := read.Model; model != nil { ```go ctx := context.TODO() -id := capabilities.NewScopedTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") +id := capabilities.NewChaosStudioTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") // alternatively `client.List(ctx, id, capabilities.DefaultListOperationOptions())` can be used to do batched pagination items, err := client.ListComplete(ctx, id, capabilities.DefaultListOperationOptions()) diff --git a/resource-manager/chaosstudio/2023-04-15-preview/capabilities/id_scopedcapability.go b/resource-manager/chaosstudio/2023-04-15-preview/capabilities/id_scopedcapability.go deleted file mode 100644 index a9bc934c0ca..00000000000 --- a/resource-manager/chaosstudio/2023-04-15-preview/capabilities/id_scopedcapability.go +++ /dev/null @@ -1,124 +0,0 @@ -package capabilities - -import ( - "fmt" - "strings" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -var _ resourceids.ResourceId = &ScopedCapabilityId{} - -// ScopedCapabilityId is a struct representing the Resource ID for a Scoped Capability -type ScopedCapabilityId struct { - Scope string - TargetName string - CapabilityName string -} - -// NewScopedCapabilityID returns a new ScopedCapabilityId struct -func NewScopedCapabilityID(scope string, targetName string, capabilityName string) ScopedCapabilityId { - return ScopedCapabilityId{ - Scope: scope, - TargetName: targetName, - CapabilityName: capabilityName, - } -} - -// ParseScopedCapabilityID parses 'input' into a ScopedCapabilityId -func ParseScopedCapabilityID(input string) (*ScopedCapabilityId, error) { - parser := resourceids.NewParserFromResourceIdType(&ScopedCapabilityId{}) - parsed, err := parser.Parse(input, false) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - id := ScopedCapabilityId{} - if err := id.FromParseResult(*parsed); err != nil { - return nil, err - } - - return &id, nil -} - -// ParseScopedCapabilityIDInsensitively parses 'input' case-insensitively into a ScopedCapabilityId -// note: this method should only be used for API response data and not user input -func ParseScopedCapabilityIDInsensitively(input string) (*ScopedCapabilityId, error) { - parser := resourceids.NewParserFromResourceIdType(&ScopedCapabilityId{}) - parsed, err := parser.Parse(input, true) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - id := ScopedCapabilityId{} - if err := id.FromParseResult(*parsed); err != nil { - return nil, err - } - - return &id, nil -} - -func (id *ScopedCapabilityId) FromParseResult(input resourceids.ParseResult) error { - var ok bool - - if id.Scope, ok = input.Parsed["scope"]; !ok { - return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) - } - - if id.TargetName, ok = input.Parsed["targetName"]; !ok { - return resourceids.NewSegmentNotSpecifiedError(id, "targetName", input) - } - - if id.CapabilityName, ok = input.Parsed["capabilityName"]; !ok { - return resourceids.NewSegmentNotSpecifiedError(id, "capabilityName", input) - } - - return nil -} - -// ValidateScopedCapabilityID checks that 'input' can be parsed as a Scoped Capability ID -func ValidateScopedCapabilityID(input interface{}, key string) (warnings []string, errors []error) { - v, ok := input.(string) - if !ok { - errors = append(errors, fmt.Errorf("expected %q to be a string", key)) - return - } - - if _, err := ParseScopedCapabilityID(v); err != nil { - errors = append(errors, err) - } - - return -} - -// ID returns the formatted Scoped Capability ID -func (id ScopedCapabilityId) ID() string { - fmtString := "/%s/providers/Microsoft.Chaos/targets/%s/capabilities/%s" - return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.TargetName, id.CapabilityName) -} - -// Segments returns a slice of Resource ID Segments which comprise this Scoped Capability ID -func (id ScopedCapabilityId) Segments() []resourceids.Segment { - return []resourceids.Segment{ - resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), - resourceids.StaticSegment("staticProviders", "providers", "providers"), - resourceids.ResourceProviderSegment("staticMicrosoftChaos", "Microsoft.Chaos", "Microsoft.Chaos"), - resourceids.StaticSegment("staticTargets", "targets", "targets"), - resourceids.UserSpecifiedSegment("targetName", "targetValue"), - resourceids.StaticSegment("staticCapabilities", "capabilities", "capabilities"), - resourceids.UserSpecifiedSegment("capabilityName", "capabilityValue"), - } -} - -// String returns a human-readable description of this Scoped Capability ID -func (id ScopedCapabilityId) String() string { - components := []string{ - fmt.Sprintf("Scope: %q", id.Scope), - fmt.Sprintf("Target Name: %q", id.TargetName), - fmt.Sprintf("Capability Name: %q", id.CapabilityName), - } - return fmt.Sprintf("Scoped Capability (%s)", strings.Join(components, "\n")) -} diff --git a/resource-manager/chaosstudio/2023-04-15-preview/capabilities/id_scopedcapability_test.go b/resource-manager/chaosstudio/2023-04-15-preview/capabilities/id_scopedcapability_test.go deleted file mode 100644 index a374f6997d9..00000000000 --- a/resource-manager/chaosstudio/2023-04-15-preview/capabilities/id_scopedcapability_test.go +++ /dev/null @@ -1,267 +0,0 @@ -package capabilities - -import ( - "testing" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -var _ resourceids.ResourceId = &ScopedCapabilityId{} - -func TestNewScopedCapabilityID(t *testing.T) { - id := NewScopedCapabilityID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue", "capabilityValue") - - if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { - t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") - } - - if id.TargetName != "targetValue" { - t.Fatalf("Expected %q but got %q for Segment 'TargetName'", id.TargetName, "targetValue") - } - - if id.CapabilityName != "capabilityValue" { - t.Fatalf("Expected %q but got %q for Segment 'CapabilityName'", id.CapabilityName, "capabilityValue") - } -} - -func TestFormatScopedCapabilityID(t *testing.T) { - actual := NewScopedCapabilityID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue", "capabilityValue").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/capabilities/capabilityValue" - if actual != expected { - t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) - } -} - -func TestParseScopedCapabilityID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *ScopedCapabilityId - }{ - { - // Incomplete URI - Input: "", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/capabilities", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/capabilities/capabilityValue", - Expected: &ScopedCapabilityId{ - Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - TargetName: "targetValue", - CapabilityName: "capabilityValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/capabilities/capabilityValue/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseScopedCapabilityID(v.Input) - if err != nil { - if v.Error { - continue - } - - t.Fatalf("Expect a value but got an error: %+v", err) - } - if v.Error { - t.Fatal("Expect an error but didn't get one") - } - - if actual.Scope != v.Expected.Scope { - t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) - } - - if actual.TargetName != v.Expected.TargetName { - t.Fatalf("Expected %q but got %q for TargetName", v.Expected.TargetName, actual.TargetName) - } - - if actual.CapabilityName != v.Expected.CapabilityName { - t.Fatalf("Expected %q but got %q for CapabilityName", v.Expected.CapabilityName, actual.CapabilityName) - } - - } -} - -func TestParseScopedCapabilityIDInsensitively(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *ScopedCapabilityId - }{ - { - // Incomplete URI - Input: "", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs/tArGeTvAlUe", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/capabilities", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs/tArGeTvAlUe/cApAbIlItIeS", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/capabilities/capabilityValue", - Expected: &ScopedCapabilityId{ - Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - TargetName: "targetValue", - CapabilityName: "capabilityValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/capabilities/capabilityValue/extra", - Error: true, - }, - { - // Valid URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs/tArGeTvAlUe/cApAbIlItIeS/cApAbIlItYvAlUe", - Expected: &ScopedCapabilityId{ - Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", - TargetName: "tArGeTvAlUe", - CapabilityName: "cApAbIlItYvAlUe", - }, - }, - { - // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs/tArGeTvAlUe/cApAbIlItIeS/cApAbIlItYvAlUe/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseScopedCapabilityIDInsensitively(v.Input) - if err != nil { - if v.Error { - continue - } - - t.Fatalf("Expect a value but got an error: %+v", err) - } - if v.Error { - t.Fatal("Expect an error but didn't get one") - } - - if actual.Scope != v.Expected.Scope { - t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) - } - - if actual.TargetName != v.Expected.TargetName { - t.Fatalf("Expected %q but got %q for TargetName", v.Expected.TargetName, actual.TargetName) - } - - if actual.CapabilityName != v.Expected.CapabilityName { - t.Fatalf("Expected %q but got %q for CapabilityName", v.Expected.CapabilityName, actual.CapabilityName) - } - - } -} - -func TestSegmentsForScopedCapabilityId(t *testing.T) { - segments := ScopedCapabilityId{}.Segments() - if len(segments) == 0 { - t.Fatalf("ScopedCapabilityId has no segments") - } - - uniqueNames := make(map[string]struct{}, 0) - for _, segment := range segments { - uniqueNames[segment.Name] = struct{}{} - } - if len(uniqueNames) != len(segments) { - t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) - } -} diff --git a/resource-manager/chaosstudio/2023-04-15-preview/capabilities/id_scopedtarget.go b/resource-manager/chaosstudio/2023-04-15-preview/capabilities/id_scopedtarget.go deleted file mode 100644 index 53355e1c6eb..00000000000 --- a/resource-manager/chaosstudio/2023-04-15-preview/capabilities/id_scopedtarget.go +++ /dev/null @@ -1,115 +0,0 @@ -package capabilities - -import ( - "fmt" - "strings" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -var _ resourceids.ResourceId = &ScopedTargetId{} - -// ScopedTargetId is a struct representing the Resource ID for a Scoped Target -type ScopedTargetId struct { - Scope string - TargetName string -} - -// NewScopedTargetID returns a new ScopedTargetId struct -func NewScopedTargetID(scope string, targetName string) ScopedTargetId { - return ScopedTargetId{ - Scope: scope, - TargetName: targetName, - } -} - -// ParseScopedTargetID parses 'input' into a ScopedTargetId -func ParseScopedTargetID(input string) (*ScopedTargetId, error) { - parser := resourceids.NewParserFromResourceIdType(&ScopedTargetId{}) - parsed, err := parser.Parse(input, false) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - id := ScopedTargetId{} - if err := id.FromParseResult(*parsed); err != nil { - return nil, err - } - - return &id, nil -} - -// ParseScopedTargetIDInsensitively parses 'input' case-insensitively into a ScopedTargetId -// note: this method should only be used for API response data and not user input -func ParseScopedTargetIDInsensitively(input string) (*ScopedTargetId, error) { - parser := resourceids.NewParserFromResourceIdType(&ScopedTargetId{}) - parsed, err := parser.Parse(input, true) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - id := ScopedTargetId{} - if err := id.FromParseResult(*parsed); err != nil { - return nil, err - } - - return &id, nil -} - -func (id *ScopedTargetId) FromParseResult(input resourceids.ParseResult) error { - var ok bool - - if id.Scope, ok = input.Parsed["scope"]; !ok { - return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) - } - - if id.TargetName, ok = input.Parsed["targetName"]; !ok { - return resourceids.NewSegmentNotSpecifiedError(id, "targetName", input) - } - - return nil -} - -// ValidateScopedTargetID checks that 'input' can be parsed as a Scoped Target ID -func ValidateScopedTargetID(input interface{}, key string) (warnings []string, errors []error) { - v, ok := input.(string) - if !ok { - errors = append(errors, fmt.Errorf("expected %q to be a string", key)) - return - } - - if _, err := ParseScopedTargetID(v); err != nil { - errors = append(errors, err) - } - - return -} - -// ID returns the formatted Scoped Target ID -func (id ScopedTargetId) ID() string { - fmtString := "/%s/providers/Microsoft.Chaos/targets/%s" - return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.TargetName) -} - -// Segments returns a slice of Resource ID Segments which comprise this Scoped Target ID -func (id ScopedTargetId) Segments() []resourceids.Segment { - return []resourceids.Segment{ - resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), - resourceids.StaticSegment("staticProviders", "providers", "providers"), - resourceids.ResourceProviderSegment("staticMicrosoftChaos", "Microsoft.Chaos", "Microsoft.Chaos"), - resourceids.StaticSegment("staticTargets", "targets", "targets"), - resourceids.UserSpecifiedSegment("targetName", "targetValue"), - } -} - -// String returns a human-readable description of this Scoped Target ID -func (id ScopedTargetId) String() string { - components := []string{ - fmt.Sprintf("Scope: %q", id.Scope), - fmt.Sprintf("Target Name: %q", id.TargetName), - } - return fmt.Sprintf("Scoped Target (%s)", strings.Join(components, "\n")) -} diff --git a/resource-manager/chaosstudio/2023-04-15-preview/capabilities/id_scopedtarget_test.go b/resource-manager/chaosstudio/2023-04-15-preview/capabilities/id_scopedtarget_test.go deleted file mode 100644 index 3ccfc2601af..00000000000 --- a/resource-manager/chaosstudio/2023-04-15-preview/capabilities/id_scopedtarget_test.go +++ /dev/null @@ -1,222 +0,0 @@ -package capabilities - -import ( - "testing" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -var _ resourceids.ResourceId = &ScopedTargetId{} - -func TestNewScopedTargetID(t *testing.T) { - id := NewScopedTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") - - if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { - t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") - } - - if id.TargetName != "targetValue" { - t.Fatalf("Expected %q but got %q for Segment 'TargetName'", id.TargetName, "targetValue") - } -} - -func TestFormatScopedTargetID(t *testing.T) { - actual := NewScopedTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue" - if actual != expected { - t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) - } -} - -func TestParseScopedTargetID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *ScopedTargetId - }{ - { - // Incomplete URI - Input: "", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue", - Expected: &ScopedTargetId{ - Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - TargetName: "targetValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseScopedTargetID(v.Input) - if err != nil { - if v.Error { - continue - } - - t.Fatalf("Expect a value but got an error: %+v", err) - } - if v.Error { - t.Fatal("Expect an error but didn't get one") - } - - if actual.Scope != v.Expected.Scope { - t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) - } - - if actual.TargetName != v.Expected.TargetName { - t.Fatalf("Expected %q but got %q for TargetName", v.Expected.TargetName, actual.TargetName) - } - - } -} - -func TestParseScopedTargetIDInsensitively(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *ScopedTargetId - }{ - { - // Incomplete URI - Input: "", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue", - Expected: &ScopedTargetId{ - Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - TargetName: "targetValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/extra", - Error: true, - }, - { - // Valid URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs/tArGeTvAlUe", - Expected: &ScopedTargetId{ - Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", - TargetName: "tArGeTvAlUe", - }, - }, - { - // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs/tArGeTvAlUe/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseScopedTargetIDInsensitively(v.Input) - if err != nil { - if v.Error { - continue - } - - t.Fatalf("Expect a value but got an error: %+v", err) - } - if v.Error { - t.Fatal("Expect an error but didn't get one") - } - - if actual.Scope != v.Expected.Scope { - t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) - } - - if actual.TargetName != v.Expected.TargetName { - t.Fatalf("Expected %q but got %q for TargetName", v.Expected.TargetName, actual.TargetName) - } - - } -} - -func TestSegmentsForScopedTargetId(t *testing.T) { - segments := ScopedTargetId{}.Segments() - if len(segments) == 0 { - t.Fatalf("ScopedTargetId has no segments") - } - - uniqueNames := make(map[string]struct{}, 0) - for _, segment := range segments { - uniqueNames[segment.Name] = struct{}{} - } - if len(uniqueNames) != len(segments) { - t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) - } -} diff --git a/resource-manager/chaosstudio/2023-04-15-preview/capabilities/method_createorupdate.go b/resource-manager/chaosstudio/2023-04-15-preview/capabilities/method_createorupdate.go index 289c7ba7f8e..463b89bd947 100644 --- a/resource-manager/chaosstudio/2023-04-15-preview/capabilities/method_createorupdate.go +++ b/resource-manager/chaosstudio/2023-04-15-preview/capabilities/method_createorupdate.go @@ -4,6 +4,7 @@ import ( "context" "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" ) @@ -18,7 +19,7 @@ type CreateOrUpdateOperationResponse struct { } // CreateOrUpdate ... -func (c CapabilitiesClient) CreateOrUpdate(ctx context.Context, id ScopedCapabilityId, input Capability) (result CreateOrUpdateOperationResponse, err error) { +func (c CapabilitiesClient) CreateOrUpdate(ctx context.Context, id commonids.ChaosStudioCapabilityId, input Capability) (result CreateOrUpdateOperationResponse, err error) { opts := client.RequestOptions{ ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ diff --git a/resource-manager/chaosstudio/2023-04-15-preview/capabilities/method_delete.go b/resource-manager/chaosstudio/2023-04-15-preview/capabilities/method_delete.go index 604f29efd58..5b1dcb3a174 100644 --- a/resource-manager/chaosstudio/2023-04-15-preview/capabilities/method_delete.go +++ b/resource-manager/chaosstudio/2023-04-15-preview/capabilities/method_delete.go @@ -4,6 +4,7 @@ import ( "context" "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" ) @@ -17,7 +18,7 @@ type DeleteOperationResponse struct { } // Delete ... -func (c CapabilitiesClient) Delete(ctx context.Context, id ScopedCapabilityId) (result DeleteOperationResponse, err error) { +func (c CapabilitiesClient) Delete(ctx context.Context, id commonids.ChaosStudioCapabilityId) (result DeleteOperationResponse, err error) { opts := client.RequestOptions{ ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ diff --git a/resource-manager/chaosstudio/2023-04-15-preview/capabilities/method_get.go b/resource-manager/chaosstudio/2023-04-15-preview/capabilities/method_get.go index 33329482911..823943c4084 100644 --- a/resource-manager/chaosstudio/2023-04-15-preview/capabilities/method_get.go +++ b/resource-manager/chaosstudio/2023-04-15-preview/capabilities/method_get.go @@ -4,6 +4,7 @@ import ( "context" "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" ) @@ -18,7 +19,7 @@ type GetOperationResponse struct { } // Get ... -func (c CapabilitiesClient) Get(ctx context.Context, id ScopedCapabilityId) (result GetOperationResponse, err error) { +func (c CapabilitiesClient) Get(ctx context.Context, id commonids.ChaosStudioCapabilityId) (result GetOperationResponse, err error) { opts := client.RequestOptions{ ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ diff --git a/resource-manager/chaosstudio/2023-04-15-preview/capabilities/method_list.go b/resource-manager/chaosstudio/2023-04-15-preview/capabilities/method_list.go index 045f0c2ffd4..c04bbab8b4e 100644 --- a/resource-manager/chaosstudio/2023-04-15-preview/capabilities/method_list.go +++ b/resource-manager/chaosstudio/2023-04-15-preview/capabilities/method_list.go @@ -5,6 +5,7 @@ import ( "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" ) @@ -51,7 +52,7 @@ func (o ListOperationOptions) ToQuery() *client.QueryParams { } // List ... -func (c CapabilitiesClient) List(ctx context.Context, id ScopedTargetId, options ListOperationOptions) (result ListOperationResponse, err error) { +func (c CapabilitiesClient) List(ctx context.Context, id commonids.ChaosStudioTargetId, options ListOperationOptions) (result ListOperationResponse, err error) { opts := client.RequestOptions{ ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ @@ -90,12 +91,12 @@ func (c CapabilitiesClient) List(ctx context.Context, id ScopedTargetId, options } // ListComplete retrieves all the results into a single object -func (c CapabilitiesClient) ListComplete(ctx context.Context, id ScopedTargetId, options ListOperationOptions) (ListCompleteResult, error) { +func (c CapabilitiesClient) ListComplete(ctx context.Context, id commonids.ChaosStudioTargetId, options ListOperationOptions) (ListCompleteResult, error) { return c.ListCompleteMatchingPredicate(ctx, id, options, CapabilityOperationPredicate{}) } // ListCompleteMatchingPredicate retrieves all the results and then applies the predicate -func (c CapabilitiesClient) ListCompleteMatchingPredicate(ctx context.Context, id ScopedTargetId, options ListOperationOptions, predicate CapabilityOperationPredicate) (result ListCompleteResult, err error) { +func (c CapabilitiesClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.ChaosStudioTargetId, options ListOperationOptions, predicate CapabilityOperationPredicate) (result ListCompleteResult, err error) { items := make([]Capability, 0) resp, err := c.List(ctx, id, options) diff --git a/resource-manager/chaosstudio/2023-04-15-preview/targets/README.md b/resource-manager/chaosstudio/2023-04-15-preview/targets/README.md index ca75d91913a..8469da3fcd9 100644 --- a/resource-manager/chaosstudio/2023-04-15-preview/targets/README.md +++ b/resource-manager/chaosstudio/2023-04-15-preview/targets/README.md @@ -24,7 +24,7 @@ client.Client.Authorizer = authorizer ```go ctx := context.TODO() -id := targets.NewScopedTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") +id := targets.NewChaosStudioTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") payload := targets.Target{ // ... @@ -45,7 +45,7 @@ if model := read.Model; model != nil { ```go ctx := context.TODO() -id := targets.NewScopedTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") +id := targets.NewChaosStudioTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") read, err := client.Delete(ctx, id) if err != nil { @@ -61,7 +61,7 @@ if model := read.Model; model != nil { ```go ctx := context.TODO() -id := targets.NewScopedTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") +id := targets.NewChaosStudioTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") read, err := client.Get(ctx, id) if err != nil { diff --git a/resource-manager/chaosstudio/2023-04-15-preview/targets/id_scopedtarget.go b/resource-manager/chaosstudio/2023-04-15-preview/targets/id_scopedtarget.go deleted file mode 100644 index 291409be87c..00000000000 --- a/resource-manager/chaosstudio/2023-04-15-preview/targets/id_scopedtarget.go +++ /dev/null @@ -1,115 +0,0 @@ -package targets - -import ( - "fmt" - "strings" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -var _ resourceids.ResourceId = &ScopedTargetId{} - -// ScopedTargetId is a struct representing the Resource ID for a Scoped Target -type ScopedTargetId struct { - Scope string - TargetName string -} - -// NewScopedTargetID returns a new ScopedTargetId struct -func NewScopedTargetID(scope string, targetName string) ScopedTargetId { - return ScopedTargetId{ - Scope: scope, - TargetName: targetName, - } -} - -// ParseScopedTargetID parses 'input' into a ScopedTargetId -func ParseScopedTargetID(input string) (*ScopedTargetId, error) { - parser := resourceids.NewParserFromResourceIdType(&ScopedTargetId{}) - parsed, err := parser.Parse(input, false) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - id := ScopedTargetId{} - if err := id.FromParseResult(*parsed); err != nil { - return nil, err - } - - return &id, nil -} - -// ParseScopedTargetIDInsensitively parses 'input' case-insensitively into a ScopedTargetId -// note: this method should only be used for API response data and not user input -func ParseScopedTargetIDInsensitively(input string) (*ScopedTargetId, error) { - parser := resourceids.NewParserFromResourceIdType(&ScopedTargetId{}) - parsed, err := parser.Parse(input, true) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - id := ScopedTargetId{} - if err := id.FromParseResult(*parsed); err != nil { - return nil, err - } - - return &id, nil -} - -func (id *ScopedTargetId) FromParseResult(input resourceids.ParseResult) error { - var ok bool - - if id.Scope, ok = input.Parsed["scope"]; !ok { - return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) - } - - if id.TargetName, ok = input.Parsed["targetName"]; !ok { - return resourceids.NewSegmentNotSpecifiedError(id, "targetName", input) - } - - return nil -} - -// ValidateScopedTargetID checks that 'input' can be parsed as a Scoped Target ID -func ValidateScopedTargetID(input interface{}, key string) (warnings []string, errors []error) { - v, ok := input.(string) - if !ok { - errors = append(errors, fmt.Errorf("expected %q to be a string", key)) - return - } - - if _, err := ParseScopedTargetID(v); err != nil { - errors = append(errors, err) - } - - return -} - -// ID returns the formatted Scoped Target ID -func (id ScopedTargetId) ID() string { - fmtString := "/%s/providers/Microsoft.Chaos/targets/%s" - return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.TargetName) -} - -// Segments returns a slice of Resource ID Segments which comprise this Scoped Target ID -func (id ScopedTargetId) Segments() []resourceids.Segment { - return []resourceids.Segment{ - resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), - resourceids.StaticSegment("staticProviders", "providers", "providers"), - resourceids.ResourceProviderSegment("staticMicrosoftChaos", "Microsoft.Chaos", "Microsoft.Chaos"), - resourceids.StaticSegment("staticTargets", "targets", "targets"), - resourceids.UserSpecifiedSegment("targetName", "targetValue"), - } -} - -// String returns a human-readable description of this Scoped Target ID -func (id ScopedTargetId) String() string { - components := []string{ - fmt.Sprintf("Scope: %q", id.Scope), - fmt.Sprintf("Target Name: %q", id.TargetName), - } - return fmt.Sprintf("Scoped Target (%s)", strings.Join(components, "\n")) -} diff --git a/resource-manager/chaosstudio/2023-04-15-preview/targets/id_scopedtarget_test.go b/resource-manager/chaosstudio/2023-04-15-preview/targets/id_scopedtarget_test.go deleted file mode 100644 index 507b746e049..00000000000 --- a/resource-manager/chaosstudio/2023-04-15-preview/targets/id_scopedtarget_test.go +++ /dev/null @@ -1,222 +0,0 @@ -package targets - -import ( - "testing" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -var _ resourceids.ResourceId = &ScopedTargetId{} - -func TestNewScopedTargetID(t *testing.T) { - id := NewScopedTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") - - if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { - t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") - } - - if id.TargetName != "targetValue" { - t.Fatalf("Expected %q but got %q for Segment 'TargetName'", id.TargetName, "targetValue") - } -} - -func TestFormatScopedTargetID(t *testing.T) { - actual := NewScopedTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue" - if actual != expected { - t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) - } -} - -func TestParseScopedTargetID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *ScopedTargetId - }{ - { - // Incomplete URI - Input: "", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue", - Expected: &ScopedTargetId{ - Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - TargetName: "targetValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseScopedTargetID(v.Input) - if err != nil { - if v.Error { - continue - } - - t.Fatalf("Expect a value but got an error: %+v", err) - } - if v.Error { - t.Fatal("Expect an error but didn't get one") - } - - if actual.Scope != v.Expected.Scope { - t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) - } - - if actual.TargetName != v.Expected.TargetName { - t.Fatalf("Expected %q but got %q for TargetName", v.Expected.TargetName, actual.TargetName) - } - - } -} - -func TestParseScopedTargetIDInsensitively(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *ScopedTargetId - }{ - { - // Incomplete URI - Input: "", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue", - Expected: &ScopedTargetId{ - Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - TargetName: "targetValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/extra", - Error: true, - }, - { - // Valid URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs/tArGeTvAlUe", - Expected: &ScopedTargetId{ - Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", - TargetName: "tArGeTvAlUe", - }, - }, - { - // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs/tArGeTvAlUe/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseScopedTargetIDInsensitively(v.Input) - if err != nil { - if v.Error { - continue - } - - t.Fatalf("Expect a value but got an error: %+v", err) - } - if v.Error { - t.Fatal("Expect an error but didn't get one") - } - - if actual.Scope != v.Expected.Scope { - t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) - } - - if actual.TargetName != v.Expected.TargetName { - t.Fatalf("Expected %q but got %q for TargetName", v.Expected.TargetName, actual.TargetName) - } - - } -} - -func TestSegmentsForScopedTargetId(t *testing.T) { - segments := ScopedTargetId{}.Segments() - if len(segments) == 0 { - t.Fatalf("ScopedTargetId has no segments") - } - - uniqueNames := make(map[string]struct{}, 0) - for _, segment := range segments { - uniqueNames[segment.Name] = struct{}{} - } - if len(uniqueNames) != len(segments) { - t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) - } -} diff --git a/resource-manager/chaosstudio/2023-04-15-preview/targets/method_createorupdate.go b/resource-manager/chaosstudio/2023-04-15-preview/targets/method_createorupdate.go index cd878889d9c..ab27172f923 100644 --- a/resource-manager/chaosstudio/2023-04-15-preview/targets/method_createorupdate.go +++ b/resource-manager/chaosstudio/2023-04-15-preview/targets/method_createorupdate.go @@ -4,6 +4,7 @@ import ( "context" "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" ) @@ -18,7 +19,7 @@ type CreateOrUpdateOperationResponse struct { } // CreateOrUpdate ... -func (c TargetsClient) CreateOrUpdate(ctx context.Context, id ScopedTargetId, input Target) (result CreateOrUpdateOperationResponse, err error) { +func (c TargetsClient) CreateOrUpdate(ctx context.Context, id commonids.ChaosStudioTargetId, input Target) (result CreateOrUpdateOperationResponse, err error) { opts := client.RequestOptions{ ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ diff --git a/resource-manager/chaosstudio/2023-04-15-preview/targets/method_delete.go b/resource-manager/chaosstudio/2023-04-15-preview/targets/method_delete.go index 4f8486a0379..0b5645f6bd2 100644 --- a/resource-manager/chaosstudio/2023-04-15-preview/targets/method_delete.go +++ b/resource-manager/chaosstudio/2023-04-15-preview/targets/method_delete.go @@ -4,6 +4,7 @@ import ( "context" "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" ) @@ -17,7 +18,7 @@ type DeleteOperationResponse struct { } // Delete ... -func (c TargetsClient) Delete(ctx context.Context, id ScopedTargetId) (result DeleteOperationResponse, err error) { +func (c TargetsClient) Delete(ctx context.Context, id commonids.ChaosStudioTargetId) (result DeleteOperationResponse, err error) { opts := client.RequestOptions{ ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ diff --git a/resource-manager/chaosstudio/2023-04-15-preview/targets/method_get.go b/resource-manager/chaosstudio/2023-04-15-preview/targets/method_get.go index bd0160969b8..1dbe63541cc 100644 --- a/resource-manager/chaosstudio/2023-04-15-preview/targets/method_get.go +++ b/resource-manager/chaosstudio/2023-04-15-preview/targets/method_get.go @@ -4,6 +4,7 @@ import ( "context" "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" ) @@ -18,7 +19,7 @@ type GetOperationResponse struct { } // Get ... -func (c TargetsClient) Get(ctx context.Context, id ScopedTargetId) (result GetOperationResponse, err error) { +func (c TargetsClient) Get(ctx context.Context, id commonids.ChaosStudioTargetId) (result GetOperationResponse, err error) { opts := client.RequestOptions{ ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ diff --git a/resource-manager/chaosstudio/2023-11-01/capabilities/README.md b/resource-manager/chaosstudio/2023-11-01/capabilities/README.md index baf82f7f6be..353fdf577bc 100644 --- a/resource-manager/chaosstudio/2023-11-01/capabilities/README.md +++ b/resource-manager/chaosstudio/2023-11-01/capabilities/README.md @@ -40,7 +40,7 @@ if model := read.Model; model != nil { ```go ctx := context.TODO() -id := capabilities.NewScopedCapabilityID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue", "capabilityValue") +id := capabilities.NewChaosStudioCapabilityID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue", "capabilityValue") payload := capabilities.Capability{ // ... @@ -61,7 +61,7 @@ if model := read.Model; model != nil { ```go ctx := context.TODO() -id := capabilities.NewScopedCapabilityID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue", "capabilityValue") +id := capabilities.NewChaosStudioCapabilityID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue", "capabilityValue") read, err := client.Delete(ctx, id) if err != nil { @@ -77,7 +77,7 @@ if model := read.Model; model != nil { ```go ctx := context.TODO() -id := capabilities.NewScopedCapabilityID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue", "capabilityValue") +id := capabilities.NewChaosStudioCapabilityID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue", "capabilityValue") read, err := client.Get(ctx, id) if err != nil { @@ -93,7 +93,7 @@ if model := read.Model; model != nil { ```go ctx := context.TODO() -id := capabilities.NewScopedTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") +id := capabilities.NewChaosStudioTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") // alternatively `client.List(ctx, id, capabilities.DefaultListOperationOptions())` can be used to do batched pagination items, err := client.ListComplete(ctx, id, capabilities.DefaultListOperationOptions()) diff --git a/resource-manager/chaosstudio/2023-11-01/capabilities/id_scopedcapability.go b/resource-manager/chaosstudio/2023-11-01/capabilities/id_scopedcapability.go deleted file mode 100644 index a9bc934c0ca..00000000000 --- a/resource-manager/chaosstudio/2023-11-01/capabilities/id_scopedcapability.go +++ /dev/null @@ -1,124 +0,0 @@ -package capabilities - -import ( - "fmt" - "strings" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -var _ resourceids.ResourceId = &ScopedCapabilityId{} - -// ScopedCapabilityId is a struct representing the Resource ID for a Scoped Capability -type ScopedCapabilityId struct { - Scope string - TargetName string - CapabilityName string -} - -// NewScopedCapabilityID returns a new ScopedCapabilityId struct -func NewScopedCapabilityID(scope string, targetName string, capabilityName string) ScopedCapabilityId { - return ScopedCapabilityId{ - Scope: scope, - TargetName: targetName, - CapabilityName: capabilityName, - } -} - -// ParseScopedCapabilityID parses 'input' into a ScopedCapabilityId -func ParseScopedCapabilityID(input string) (*ScopedCapabilityId, error) { - parser := resourceids.NewParserFromResourceIdType(&ScopedCapabilityId{}) - parsed, err := parser.Parse(input, false) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - id := ScopedCapabilityId{} - if err := id.FromParseResult(*parsed); err != nil { - return nil, err - } - - return &id, nil -} - -// ParseScopedCapabilityIDInsensitively parses 'input' case-insensitively into a ScopedCapabilityId -// note: this method should only be used for API response data and not user input -func ParseScopedCapabilityIDInsensitively(input string) (*ScopedCapabilityId, error) { - parser := resourceids.NewParserFromResourceIdType(&ScopedCapabilityId{}) - parsed, err := parser.Parse(input, true) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - id := ScopedCapabilityId{} - if err := id.FromParseResult(*parsed); err != nil { - return nil, err - } - - return &id, nil -} - -func (id *ScopedCapabilityId) FromParseResult(input resourceids.ParseResult) error { - var ok bool - - if id.Scope, ok = input.Parsed["scope"]; !ok { - return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) - } - - if id.TargetName, ok = input.Parsed["targetName"]; !ok { - return resourceids.NewSegmentNotSpecifiedError(id, "targetName", input) - } - - if id.CapabilityName, ok = input.Parsed["capabilityName"]; !ok { - return resourceids.NewSegmentNotSpecifiedError(id, "capabilityName", input) - } - - return nil -} - -// ValidateScopedCapabilityID checks that 'input' can be parsed as a Scoped Capability ID -func ValidateScopedCapabilityID(input interface{}, key string) (warnings []string, errors []error) { - v, ok := input.(string) - if !ok { - errors = append(errors, fmt.Errorf("expected %q to be a string", key)) - return - } - - if _, err := ParseScopedCapabilityID(v); err != nil { - errors = append(errors, err) - } - - return -} - -// ID returns the formatted Scoped Capability ID -func (id ScopedCapabilityId) ID() string { - fmtString := "/%s/providers/Microsoft.Chaos/targets/%s/capabilities/%s" - return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.TargetName, id.CapabilityName) -} - -// Segments returns a slice of Resource ID Segments which comprise this Scoped Capability ID -func (id ScopedCapabilityId) Segments() []resourceids.Segment { - return []resourceids.Segment{ - resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), - resourceids.StaticSegment("staticProviders", "providers", "providers"), - resourceids.ResourceProviderSegment("staticMicrosoftChaos", "Microsoft.Chaos", "Microsoft.Chaos"), - resourceids.StaticSegment("staticTargets", "targets", "targets"), - resourceids.UserSpecifiedSegment("targetName", "targetValue"), - resourceids.StaticSegment("staticCapabilities", "capabilities", "capabilities"), - resourceids.UserSpecifiedSegment("capabilityName", "capabilityValue"), - } -} - -// String returns a human-readable description of this Scoped Capability ID -func (id ScopedCapabilityId) String() string { - components := []string{ - fmt.Sprintf("Scope: %q", id.Scope), - fmt.Sprintf("Target Name: %q", id.TargetName), - fmt.Sprintf("Capability Name: %q", id.CapabilityName), - } - return fmt.Sprintf("Scoped Capability (%s)", strings.Join(components, "\n")) -} diff --git a/resource-manager/chaosstudio/2023-11-01/capabilities/id_scopedcapability_test.go b/resource-manager/chaosstudio/2023-11-01/capabilities/id_scopedcapability_test.go deleted file mode 100644 index a374f6997d9..00000000000 --- a/resource-manager/chaosstudio/2023-11-01/capabilities/id_scopedcapability_test.go +++ /dev/null @@ -1,267 +0,0 @@ -package capabilities - -import ( - "testing" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -var _ resourceids.ResourceId = &ScopedCapabilityId{} - -func TestNewScopedCapabilityID(t *testing.T) { - id := NewScopedCapabilityID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue", "capabilityValue") - - if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { - t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") - } - - if id.TargetName != "targetValue" { - t.Fatalf("Expected %q but got %q for Segment 'TargetName'", id.TargetName, "targetValue") - } - - if id.CapabilityName != "capabilityValue" { - t.Fatalf("Expected %q but got %q for Segment 'CapabilityName'", id.CapabilityName, "capabilityValue") - } -} - -func TestFormatScopedCapabilityID(t *testing.T) { - actual := NewScopedCapabilityID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue", "capabilityValue").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/capabilities/capabilityValue" - if actual != expected { - t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) - } -} - -func TestParseScopedCapabilityID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *ScopedCapabilityId - }{ - { - // Incomplete URI - Input: "", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/capabilities", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/capabilities/capabilityValue", - Expected: &ScopedCapabilityId{ - Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - TargetName: "targetValue", - CapabilityName: "capabilityValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/capabilities/capabilityValue/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseScopedCapabilityID(v.Input) - if err != nil { - if v.Error { - continue - } - - t.Fatalf("Expect a value but got an error: %+v", err) - } - if v.Error { - t.Fatal("Expect an error but didn't get one") - } - - if actual.Scope != v.Expected.Scope { - t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) - } - - if actual.TargetName != v.Expected.TargetName { - t.Fatalf("Expected %q but got %q for TargetName", v.Expected.TargetName, actual.TargetName) - } - - if actual.CapabilityName != v.Expected.CapabilityName { - t.Fatalf("Expected %q but got %q for CapabilityName", v.Expected.CapabilityName, actual.CapabilityName) - } - - } -} - -func TestParseScopedCapabilityIDInsensitively(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *ScopedCapabilityId - }{ - { - // Incomplete URI - Input: "", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs/tArGeTvAlUe", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/capabilities", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs/tArGeTvAlUe/cApAbIlItIeS", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/capabilities/capabilityValue", - Expected: &ScopedCapabilityId{ - Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - TargetName: "targetValue", - CapabilityName: "capabilityValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/capabilities/capabilityValue/extra", - Error: true, - }, - { - // Valid URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs/tArGeTvAlUe/cApAbIlItIeS/cApAbIlItYvAlUe", - Expected: &ScopedCapabilityId{ - Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", - TargetName: "tArGeTvAlUe", - CapabilityName: "cApAbIlItYvAlUe", - }, - }, - { - // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs/tArGeTvAlUe/cApAbIlItIeS/cApAbIlItYvAlUe/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseScopedCapabilityIDInsensitively(v.Input) - if err != nil { - if v.Error { - continue - } - - t.Fatalf("Expect a value but got an error: %+v", err) - } - if v.Error { - t.Fatal("Expect an error but didn't get one") - } - - if actual.Scope != v.Expected.Scope { - t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) - } - - if actual.TargetName != v.Expected.TargetName { - t.Fatalf("Expected %q but got %q for TargetName", v.Expected.TargetName, actual.TargetName) - } - - if actual.CapabilityName != v.Expected.CapabilityName { - t.Fatalf("Expected %q but got %q for CapabilityName", v.Expected.CapabilityName, actual.CapabilityName) - } - - } -} - -func TestSegmentsForScopedCapabilityId(t *testing.T) { - segments := ScopedCapabilityId{}.Segments() - if len(segments) == 0 { - t.Fatalf("ScopedCapabilityId has no segments") - } - - uniqueNames := make(map[string]struct{}, 0) - for _, segment := range segments { - uniqueNames[segment.Name] = struct{}{} - } - if len(uniqueNames) != len(segments) { - t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) - } -} diff --git a/resource-manager/chaosstudio/2023-11-01/capabilities/id_scopedtarget.go b/resource-manager/chaosstudio/2023-11-01/capabilities/id_scopedtarget.go deleted file mode 100644 index 53355e1c6eb..00000000000 --- a/resource-manager/chaosstudio/2023-11-01/capabilities/id_scopedtarget.go +++ /dev/null @@ -1,115 +0,0 @@ -package capabilities - -import ( - "fmt" - "strings" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -var _ resourceids.ResourceId = &ScopedTargetId{} - -// ScopedTargetId is a struct representing the Resource ID for a Scoped Target -type ScopedTargetId struct { - Scope string - TargetName string -} - -// NewScopedTargetID returns a new ScopedTargetId struct -func NewScopedTargetID(scope string, targetName string) ScopedTargetId { - return ScopedTargetId{ - Scope: scope, - TargetName: targetName, - } -} - -// ParseScopedTargetID parses 'input' into a ScopedTargetId -func ParseScopedTargetID(input string) (*ScopedTargetId, error) { - parser := resourceids.NewParserFromResourceIdType(&ScopedTargetId{}) - parsed, err := parser.Parse(input, false) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - id := ScopedTargetId{} - if err := id.FromParseResult(*parsed); err != nil { - return nil, err - } - - return &id, nil -} - -// ParseScopedTargetIDInsensitively parses 'input' case-insensitively into a ScopedTargetId -// note: this method should only be used for API response data and not user input -func ParseScopedTargetIDInsensitively(input string) (*ScopedTargetId, error) { - parser := resourceids.NewParserFromResourceIdType(&ScopedTargetId{}) - parsed, err := parser.Parse(input, true) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - id := ScopedTargetId{} - if err := id.FromParseResult(*parsed); err != nil { - return nil, err - } - - return &id, nil -} - -func (id *ScopedTargetId) FromParseResult(input resourceids.ParseResult) error { - var ok bool - - if id.Scope, ok = input.Parsed["scope"]; !ok { - return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) - } - - if id.TargetName, ok = input.Parsed["targetName"]; !ok { - return resourceids.NewSegmentNotSpecifiedError(id, "targetName", input) - } - - return nil -} - -// ValidateScopedTargetID checks that 'input' can be parsed as a Scoped Target ID -func ValidateScopedTargetID(input interface{}, key string) (warnings []string, errors []error) { - v, ok := input.(string) - if !ok { - errors = append(errors, fmt.Errorf("expected %q to be a string", key)) - return - } - - if _, err := ParseScopedTargetID(v); err != nil { - errors = append(errors, err) - } - - return -} - -// ID returns the formatted Scoped Target ID -func (id ScopedTargetId) ID() string { - fmtString := "/%s/providers/Microsoft.Chaos/targets/%s" - return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.TargetName) -} - -// Segments returns a slice of Resource ID Segments which comprise this Scoped Target ID -func (id ScopedTargetId) Segments() []resourceids.Segment { - return []resourceids.Segment{ - resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), - resourceids.StaticSegment("staticProviders", "providers", "providers"), - resourceids.ResourceProviderSegment("staticMicrosoftChaos", "Microsoft.Chaos", "Microsoft.Chaos"), - resourceids.StaticSegment("staticTargets", "targets", "targets"), - resourceids.UserSpecifiedSegment("targetName", "targetValue"), - } -} - -// String returns a human-readable description of this Scoped Target ID -func (id ScopedTargetId) String() string { - components := []string{ - fmt.Sprintf("Scope: %q", id.Scope), - fmt.Sprintf("Target Name: %q", id.TargetName), - } - return fmt.Sprintf("Scoped Target (%s)", strings.Join(components, "\n")) -} diff --git a/resource-manager/chaosstudio/2023-11-01/capabilities/id_scopedtarget_test.go b/resource-manager/chaosstudio/2023-11-01/capabilities/id_scopedtarget_test.go deleted file mode 100644 index 3ccfc2601af..00000000000 --- a/resource-manager/chaosstudio/2023-11-01/capabilities/id_scopedtarget_test.go +++ /dev/null @@ -1,222 +0,0 @@ -package capabilities - -import ( - "testing" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -var _ resourceids.ResourceId = &ScopedTargetId{} - -func TestNewScopedTargetID(t *testing.T) { - id := NewScopedTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") - - if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { - t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") - } - - if id.TargetName != "targetValue" { - t.Fatalf("Expected %q but got %q for Segment 'TargetName'", id.TargetName, "targetValue") - } -} - -func TestFormatScopedTargetID(t *testing.T) { - actual := NewScopedTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue" - if actual != expected { - t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) - } -} - -func TestParseScopedTargetID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *ScopedTargetId - }{ - { - // Incomplete URI - Input: "", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue", - Expected: &ScopedTargetId{ - Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - TargetName: "targetValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseScopedTargetID(v.Input) - if err != nil { - if v.Error { - continue - } - - t.Fatalf("Expect a value but got an error: %+v", err) - } - if v.Error { - t.Fatal("Expect an error but didn't get one") - } - - if actual.Scope != v.Expected.Scope { - t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) - } - - if actual.TargetName != v.Expected.TargetName { - t.Fatalf("Expected %q but got %q for TargetName", v.Expected.TargetName, actual.TargetName) - } - - } -} - -func TestParseScopedTargetIDInsensitively(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *ScopedTargetId - }{ - { - // Incomplete URI - Input: "", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue", - Expected: &ScopedTargetId{ - Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - TargetName: "targetValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/extra", - Error: true, - }, - { - // Valid URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs/tArGeTvAlUe", - Expected: &ScopedTargetId{ - Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", - TargetName: "tArGeTvAlUe", - }, - }, - { - // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs/tArGeTvAlUe/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseScopedTargetIDInsensitively(v.Input) - if err != nil { - if v.Error { - continue - } - - t.Fatalf("Expect a value but got an error: %+v", err) - } - if v.Error { - t.Fatal("Expect an error but didn't get one") - } - - if actual.Scope != v.Expected.Scope { - t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) - } - - if actual.TargetName != v.Expected.TargetName { - t.Fatalf("Expected %q but got %q for TargetName", v.Expected.TargetName, actual.TargetName) - } - - } -} - -func TestSegmentsForScopedTargetId(t *testing.T) { - segments := ScopedTargetId{}.Segments() - if len(segments) == 0 { - t.Fatalf("ScopedTargetId has no segments") - } - - uniqueNames := make(map[string]struct{}, 0) - for _, segment := range segments { - uniqueNames[segment.Name] = struct{}{} - } - if len(uniqueNames) != len(segments) { - t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) - } -} diff --git a/resource-manager/chaosstudio/2023-11-01/capabilities/method_createorupdate.go b/resource-manager/chaosstudio/2023-11-01/capabilities/method_createorupdate.go index 289c7ba7f8e..463b89bd947 100644 --- a/resource-manager/chaosstudio/2023-11-01/capabilities/method_createorupdate.go +++ b/resource-manager/chaosstudio/2023-11-01/capabilities/method_createorupdate.go @@ -4,6 +4,7 @@ import ( "context" "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" ) @@ -18,7 +19,7 @@ type CreateOrUpdateOperationResponse struct { } // CreateOrUpdate ... -func (c CapabilitiesClient) CreateOrUpdate(ctx context.Context, id ScopedCapabilityId, input Capability) (result CreateOrUpdateOperationResponse, err error) { +func (c CapabilitiesClient) CreateOrUpdate(ctx context.Context, id commonids.ChaosStudioCapabilityId, input Capability) (result CreateOrUpdateOperationResponse, err error) { opts := client.RequestOptions{ ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ diff --git a/resource-manager/chaosstudio/2023-11-01/capabilities/method_delete.go b/resource-manager/chaosstudio/2023-11-01/capabilities/method_delete.go index 604f29efd58..5b1dcb3a174 100644 --- a/resource-manager/chaosstudio/2023-11-01/capabilities/method_delete.go +++ b/resource-manager/chaosstudio/2023-11-01/capabilities/method_delete.go @@ -4,6 +4,7 @@ import ( "context" "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" ) @@ -17,7 +18,7 @@ type DeleteOperationResponse struct { } // Delete ... -func (c CapabilitiesClient) Delete(ctx context.Context, id ScopedCapabilityId) (result DeleteOperationResponse, err error) { +func (c CapabilitiesClient) Delete(ctx context.Context, id commonids.ChaosStudioCapabilityId) (result DeleteOperationResponse, err error) { opts := client.RequestOptions{ ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ diff --git a/resource-manager/chaosstudio/2023-11-01/capabilities/method_get.go b/resource-manager/chaosstudio/2023-11-01/capabilities/method_get.go index 33329482911..823943c4084 100644 --- a/resource-manager/chaosstudio/2023-11-01/capabilities/method_get.go +++ b/resource-manager/chaosstudio/2023-11-01/capabilities/method_get.go @@ -4,6 +4,7 @@ import ( "context" "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" ) @@ -18,7 +19,7 @@ type GetOperationResponse struct { } // Get ... -func (c CapabilitiesClient) Get(ctx context.Context, id ScopedCapabilityId) (result GetOperationResponse, err error) { +func (c CapabilitiesClient) Get(ctx context.Context, id commonids.ChaosStudioCapabilityId) (result GetOperationResponse, err error) { opts := client.RequestOptions{ ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ diff --git a/resource-manager/chaosstudio/2023-11-01/capabilities/method_list.go b/resource-manager/chaosstudio/2023-11-01/capabilities/method_list.go index 045f0c2ffd4..c04bbab8b4e 100644 --- a/resource-manager/chaosstudio/2023-11-01/capabilities/method_list.go +++ b/resource-manager/chaosstudio/2023-11-01/capabilities/method_list.go @@ -5,6 +5,7 @@ import ( "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" ) @@ -51,7 +52,7 @@ func (o ListOperationOptions) ToQuery() *client.QueryParams { } // List ... -func (c CapabilitiesClient) List(ctx context.Context, id ScopedTargetId, options ListOperationOptions) (result ListOperationResponse, err error) { +func (c CapabilitiesClient) List(ctx context.Context, id commonids.ChaosStudioTargetId, options ListOperationOptions) (result ListOperationResponse, err error) { opts := client.RequestOptions{ ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ @@ -90,12 +91,12 @@ func (c CapabilitiesClient) List(ctx context.Context, id ScopedTargetId, options } // ListComplete retrieves all the results into a single object -func (c CapabilitiesClient) ListComplete(ctx context.Context, id ScopedTargetId, options ListOperationOptions) (ListCompleteResult, error) { +func (c CapabilitiesClient) ListComplete(ctx context.Context, id commonids.ChaosStudioTargetId, options ListOperationOptions) (ListCompleteResult, error) { return c.ListCompleteMatchingPredicate(ctx, id, options, CapabilityOperationPredicate{}) } // ListCompleteMatchingPredicate retrieves all the results and then applies the predicate -func (c CapabilitiesClient) ListCompleteMatchingPredicate(ctx context.Context, id ScopedTargetId, options ListOperationOptions, predicate CapabilityOperationPredicate) (result ListCompleteResult, err error) { +func (c CapabilitiesClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.ChaosStudioTargetId, options ListOperationOptions, predicate CapabilityOperationPredicate) (result ListCompleteResult, err error) { items := make([]Capability, 0) resp, err := c.List(ctx, id, options) diff --git a/resource-manager/chaosstudio/2023-11-01/targets/README.md b/resource-manager/chaosstudio/2023-11-01/targets/README.md index d7899526b1d..7d022bae47c 100644 --- a/resource-manager/chaosstudio/2023-11-01/targets/README.md +++ b/resource-manager/chaosstudio/2023-11-01/targets/README.md @@ -24,7 +24,7 @@ client.Client.Authorizer = authorizer ```go ctx := context.TODO() -id := targets.NewScopedTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") +id := targets.NewChaosStudioTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") payload := targets.Target{ // ... @@ -45,7 +45,7 @@ if model := read.Model; model != nil { ```go ctx := context.TODO() -id := targets.NewScopedTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") +id := targets.NewChaosStudioTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") read, err := client.Delete(ctx, id) if err != nil { @@ -61,7 +61,7 @@ if model := read.Model; model != nil { ```go ctx := context.TODO() -id := targets.NewScopedTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") +id := targets.NewChaosStudioTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") read, err := client.Get(ctx, id) if err != nil { diff --git a/resource-manager/chaosstudio/2023-11-01/targets/id_scopedtarget.go b/resource-manager/chaosstudio/2023-11-01/targets/id_scopedtarget.go deleted file mode 100644 index 291409be87c..00000000000 --- a/resource-manager/chaosstudio/2023-11-01/targets/id_scopedtarget.go +++ /dev/null @@ -1,115 +0,0 @@ -package targets - -import ( - "fmt" - "strings" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -var _ resourceids.ResourceId = &ScopedTargetId{} - -// ScopedTargetId is a struct representing the Resource ID for a Scoped Target -type ScopedTargetId struct { - Scope string - TargetName string -} - -// NewScopedTargetID returns a new ScopedTargetId struct -func NewScopedTargetID(scope string, targetName string) ScopedTargetId { - return ScopedTargetId{ - Scope: scope, - TargetName: targetName, - } -} - -// ParseScopedTargetID parses 'input' into a ScopedTargetId -func ParseScopedTargetID(input string) (*ScopedTargetId, error) { - parser := resourceids.NewParserFromResourceIdType(&ScopedTargetId{}) - parsed, err := parser.Parse(input, false) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - id := ScopedTargetId{} - if err := id.FromParseResult(*parsed); err != nil { - return nil, err - } - - return &id, nil -} - -// ParseScopedTargetIDInsensitively parses 'input' case-insensitively into a ScopedTargetId -// note: this method should only be used for API response data and not user input -func ParseScopedTargetIDInsensitively(input string) (*ScopedTargetId, error) { - parser := resourceids.NewParserFromResourceIdType(&ScopedTargetId{}) - parsed, err := parser.Parse(input, true) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - id := ScopedTargetId{} - if err := id.FromParseResult(*parsed); err != nil { - return nil, err - } - - return &id, nil -} - -func (id *ScopedTargetId) FromParseResult(input resourceids.ParseResult) error { - var ok bool - - if id.Scope, ok = input.Parsed["scope"]; !ok { - return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) - } - - if id.TargetName, ok = input.Parsed["targetName"]; !ok { - return resourceids.NewSegmentNotSpecifiedError(id, "targetName", input) - } - - return nil -} - -// ValidateScopedTargetID checks that 'input' can be parsed as a Scoped Target ID -func ValidateScopedTargetID(input interface{}, key string) (warnings []string, errors []error) { - v, ok := input.(string) - if !ok { - errors = append(errors, fmt.Errorf("expected %q to be a string", key)) - return - } - - if _, err := ParseScopedTargetID(v); err != nil { - errors = append(errors, err) - } - - return -} - -// ID returns the formatted Scoped Target ID -func (id ScopedTargetId) ID() string { - fmtString := "/%s/providers/Microsoft.Chaos/targets/%s" - return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.TargetName) -} - -// Segments returns a slice of Resource ID Segments which comprise this Scoped Target ID -func (id ScopedTargetId) Segments() []resourceids.Segment { - return []resourceids.Segment{ - resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), - resourceids.StaticSegment("staticProviders", "providers", "providers"), - resourceids.ResourceProviderSegment("staticMicrosoftChaos", "Microsoft.Chaos", "Microsoft.Chaos"), - resourceids.StaticSegment("staticTargets", "targets", "targets"), - resourceids.UserSpecifiedSegment("targetName", "targetValue"), - } -} - -// String returns a human-readable description of this Scoped Target ID -func (id ScopedTargetId) String() string { - components := []string{ - fmt.Sprintf("Scope: %q", id.Scope), - fmt.Sprintf("Target Name: %q", id.TargetName), - } - return fmt.Sprintf("Scoped Target (%s)", strings.Join(components, "\n")) -} diff --git a/resource-manager/chaosstudio/2023-11-01/targets/id_scopedtarget_test.go b/resource-manager/chaosstudio/2023-11-01/targets/id_scopedtarget_test.go deleted file mode 100644 index 507b746e049..00000000000 --- a/resource-manager/chaosstudio/2023-11-01/targets/id_scopedtarget_test.go +++ /dev/null @@ -1,222 +0,0 @@ -package targets - -import ( - "testing" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -var _ resourceids.ResourceId = &ScopedTargetId{} - -func TestNewScopedTargetID(t *testing.T) { - id := NewScopedTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") - - if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { - t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") - } - - if id.TargetName != "targetValue" { - t.Fatalf("Expected %q but got %q for Segment 'TargetName'", id.TargetName, "targetValue") - } -} - -func TestFormatScopedTargetID(t *testing.T) { - actual := NewScopedTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue" - if actual != expected { - t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) - } -} - -func TestParseScopedTargetID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *ScopedTargetId - }{ - { - // Incomplete URI - Input: "", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue", - Expected: &ScopedTargetId{ - Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - TargetName: "targetValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseScopedTargetID(v.Input) - if err != nil { - if v.Error { - continue - } - - t.Fatalf("Expect a value but got an error: %+v", err) - } - if v.Error { - t.Fatal("Expect an error but didn't get one") - } - - if actual.Scope != v.Expected.Scope { - t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) - } - - if actual.TargetName != v.Expected.TargetName { - t.Fatalf("Expected %q but got %q for TargetName", v.Expected.TargetName, actual.TargetName) - } - - } -} - -func TestParseScopedTargetIDInsensitively(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *ScopedTargetId - }{ - { - // Incomplete URI - Input: "", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue", - Expected: &ScopedTargetId{ - Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - TargetName: "targetValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/extra", - Error: true, - }, - { - // Valid URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs/tArGeTvAlUe", - Expected: &ScopedTargetId{ - Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", - TargetName: "tArGeTvAlUe", - }, - }, - { - // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs/tArGeTvAlUe/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseScopedTargetIDInsensitively(v.Input) - if err != nil { - if v.Error { - continue - } - - t.Fatalf("Expect a value but got an error: %+v", err) - } - if v.Error { - t.Fatal("Expect an error but didn't get one") - } - - if actual.Scope != v.Expected.Scope { - t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) - } - - if actual.TargetName != v.Expected.TargetName { - t.Fatalf("Expected %q but got %q for TargetName", v.Expected.TargetName, actual.TargetName) - } - - } -} - -func TestSegmentsForScopedTargetId(t *testing.T) { - segments := ScopedTargetId{}.Segments() - if len(segments) == 0 { - t.Fatalf("ScopedTargetId has no segments") - } - - uniqueNames := make(map[string]struct{}, 0) - for _, segment := range segments { - uniqueNames[segment.Name] = struct{}{} - } - if len(uniqueNames) != len(segments) { - t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) - } -} diff --git a/resource-manager/chaosstudio/2023-11-01/targets/method_createorupdate.go b/resource-manager/chaosstudio/2023-11-01/targets/method_createorupdate.go index cd878889d9c..ab27172f923 100644 --- a/resource-manager/chaosstudio/2023-11-01/targets/method_createorupdate.go +++ b/resource-manager/chaosstudio/2023-11-01/targets/method_createorupdate.go @@ -4,6 +4,7 @@ import ( "context" "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" ) @@ -18,7 +19,7 @@ type CreateOrUpdateOperationResponse struct { } // CreateOrUpdate ... -func (c TargetsClient) CreateOrUpdate(ctx context.Context, id ScopedTargetId, input Target) (result CreateOrUpdateOperationResponse, err error) { +func (c TargetsClient) CreateOrUpdate(ctx context.Context, id commonids.ChaosStudioTargetId, input Target) (result CreateOrUpdateOperationResponse, err error) { opts := client.RequestOptions{ ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ diff --git a/resource-manager/chaosstudio/2023-11-01/targets/method_delete.go b/resource-manager/chaosstudio/2023-11-01/targets/method_delete.go index 4f8486a0379..0b5645f6bd2 100644 --- a/resource-manager/chaosstudio/2023-11-01/targets/method_delete.go +++ b/resource-manager/chaosstudio/2023-11-01/targets/method_delete.go @@ -4,6 +4,7 @@ import ( "context" "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" ) @@ -17,7 +18,7 @@ type DeleteOperationResponse struct { } // Delete ... -func (c TargetsClient) Delete(ctx context.Context, id ScopedTargetId) (result DeleteOperationResponse, err error) { +func (c TargetsClient) Delete(ctx context.Context, id commonids.ChaosStudioTargetId) (result DeleteOperationResponse, err error) { opts := client.RequestOptions{ ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ diff --git a/resource-manager/chaosstudio/2023-11-01/targets/method_get.go b/resource-manager/chaosstudio/2023-11-01/targets/method_get.go index bd0160969b8..1dbe63541cc 100644 --- a/resource-manager/chaosstudio/2023-11-01/targets/method_get.go +++ b/resource-manager/chaosstudio/2023-11-01/targets/method_get.go @@ -4,6 +4,7 @@ import ( "context" "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" ) @@ -18,7 +19,7 @@ type GetOperationResponse struct { } // Get ... -func (c TargetsClient) Get(ctx context.Context, id ScopedTargetId) (result GetOperationResponse, err error) { +func (c TargetsClient) Get(ctx context.Context, id commonids.ChaosStudioTargetId) (result GetOperationResponse, err error) { opts := client.RequestOptions{ ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ diff --git a/resource-manager/chaosstudio/2024-01-01/capabilities/README.md b/resource-manager/chaosstudio/2024-01-01/capabilities/README.md index 305bdf93942..246bcf6fde4 100644 --- a/resource-manager/chaosstudio/2024-01-01/capabilities/README.md +++ b/resource-manager/chaosstudio/2024-01-01/capabilities/README.md @@ -40,7 +40,7 @@ if model := read.Model; model != nil { ```go ctx := context.TODO() -id := capabilities.NewScopedCapabilityID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue", "capabilityValue") +id := capabilities.NewChaosStudioCapabilityID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue", "capabilityValue") payload := capabilities.Capability{ // ... @@ -61,7 +61,7 @@ if model := read.Model; model != nil { ```go ctx := context.TODO() -id := capabilities.NewScopedCapabilityID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue", "capabilityValue") +id := capabilities.NewChaosStudioCapabilityID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue", "capabilityValue") read, err := client.Delete(ctx, id) if err != nil { @@ -77,7 +77,7 @@ if model := read.Model; model != nil { ```go ctx := context.TODO() -id := capabilities.NewScopedCapabilityID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue", "capabilityValue") +id := capabilities.NewChaosStudioCapabilityID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue", "capabilityValue") read, err := client.Get(ctx, id) if err != nil { @@ -93,7 +93,7 @@ if model := read.Model; model != nil { ```go ctx := context.TODO() -id := capabilities.NewScopedTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") +id := capabilities.NewChaosStudioTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") // alternatively `client.List(ctx, id, capabilities.DefaultListOperationOptions())` can be used to do batched pagination items, err := client.ListComplete(ctx, id, capabilities.DefaultListOperationOptions()) diff --git a/resource-manager/chaosstudio/2024-01-01/capabilities/id_scopedcapability.go b/resource-manager/chaosstudio/2024-01-01/capabilities/id_scopedcapability.go deleted file mode 100644 index a9bc934c0ca..00000000000 --- a/resource-manager/chaosstudio/2024-01-01/capabilities/id_scopedcapability.go +++ /dev/null @@ -1,124 +0,0 @@ -package capabilities - -import ( - "fmt" - "strings" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -var _ resourceids.ResourceId = &ScopedCapabilityId{} - -// ScopedCapabilityId is a struct representing the Resource ID for a Scoped Capability -type ScopedCapabilityId struct { - Scope string - TargetName string - CapabilityName string -} - -// NewScopedCapabilityID returns a new ScopedCapabilityId struct -func NewScopedCapabilityID(scope string, targetName string, capabilityName string) ScopedCapabilityId { - return ScopedCapabilityId{ - Scope: scope, - TargetName: targetName, - CapabilityName: capabilityName, - } -} - -// ParseScopedCapabilityID parses 'input' into a ScopedCapabilityId -func ParseScopedCapabilityID(input string) (*ScopedCapabilityId, error) { - parser := resourceids.NewParserFromResourceIdType(&ScopedCapabilityId{}) - parsed, err := parser.Parse(input, false) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - id := ScopedCapabilityId{} - if err := id.FromParseResult(*parsed); err != nil { - return nil, err - } - - return &id, nil -} - -// ParseScopedCapabilityIDInsensitively parses 'input' case-insensitively into a ScopedCapabilityId -// note: this method should only be used for API response data and not user input -func ParseScopedCapabilityIDInsensitively(input string) (*ScopedCapabilityId, error) { - parser := resourceids.NewParserFromResourceIdType(&ScopedCapabilityId{}) - parsed, err := parser.Parse(input, true) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - id := ScopedCapabilityId{} - if err := id.FromParseResult(*parsed); err != nil { - return nil, err - } - - return &id, nil -} - -func (id *ScopedCapabilityId) FromParseResult(input resourceids.ParseResult) error { - var ok bool - - if id.Scope, ok = input.Parsed["scope"]; !ok { - return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) - } - - if id.TargetName, ok = input.Parsed["targetName"]; !ok { - return resourceids.NewSegmentNotSpecifiedError(id, "targetName", input) - } - - if id.CapabilityName, ok = input.Parsed["capabilityName"]; !ok { - return resourceids.NewSegmentNotSpecifiedError(id, "capabilityName", input) - } - - return nil -} - -// ValidateScopedCapabilityID checks that 'input' can be parsed as a Scoped Capability ID -func ValidateScopedCapabilityID(input interface{}, key string) (warnings []string, errors []error) { - v, ok := input.(string) - if !ok { - errors = append(errors, fmt.Errorf("expected %q to be a string", key)) - return - } - - if _, err := ParseScopedCapabilityID(v); err != nil { - errors = append(errors, err) - } - - return -} - -// ID returns the formatted Scoped Capability ID -func (id ScopedCapabilityId) ID() string { - fmtString := "/%s/providers/Microsoft.Chaos/targets/%s/capabilities/%s" - return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.TargetName, id.CapabilityName) -} - -// Segments returns a slice of Resource ID Segments which comprise this Scoped Capability ID -func (id ScopedCapabilityId) Segments() []resourceids.Segment { - return []resourceids.Segment{ - resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), - resourceids.StaticSegment("staticProviders", "providers", "providers"), - resourceids.ResourceProviderSegment("staticMicrosoftChaos", "Microsoft.Chaos", "Microsoft.Chaos"), - resourceids.StaticSegment("staticTargets", "targets", "targets"), - resourceids.UserSpecifiedSegment("targetName", "targetValue"), - resourceids.StaticSegment("staticCapabilities", "capabilities", "capabilities"), - resourceids.UserSpecifiedSegment("capabilityName", "capabilityValue"), - } -} - -// String returns a human-readable description of this Scoped Capability ID -func (id ScopedCapabilityId) String() string { - components := []string{ - fmt.Sprintf("Scope: %q", id.Scope), - fmt.Sprintf("Target Name: %q", id.TargetName), - fmt.Sprintf("Capability Name: %q", id.CapabilityName), - } - return fmt.Sprintf("Scoped Capability (%s)", strings.Join(components, "\n")) -} diff --git a/resource-manager/chaosstudio/2024-01-01/capabilities/id_scopedcapability_test.go b/resource-manager/chaosstudio/2024-01-01/capabilities/id_scopedcapability_test.go deleted file mode 100644 index a374f6997d9..00000000000 --- a/resource-manager/chaosstudio/2024-01-01/capabilities/id_scopedcapability_test.go +++ /dev/null @@ -1,267 +0,0 @@ -package capabilities - -import ( - "testing" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -var _ resourceids.ResourceId = &ScopedCapabilityId{} - -func TestNewScopedCapabilityID(t *testing.T) { - id := NewScopedCapabilityID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue", "capabilityValue") - - if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { - t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") - } - - if id.TargetName != "targetValue" { - t.Fatalf("Expected %q but got %q for Segment 'TargetName'", id.TargetName, "targetValue") - } - - if id.CapabilityName != "capabilityValue" { - t.Fatalf("Expected %q but got %q for Segment 'CapabilityName'", id.CapabilityName, "capabilityValue") - } -} - -func TestFormatScopedCapabilityID(t *testing.T) { - actual := NewScopedCapabilityID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue", "capabilityValue").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/capabilities/capabilityValue" - if actual != expected { - t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) - } -} - -func TestParseScopedCapabilityID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *ScopedCapabilityId - }{ - { - // Incomplete URI - Input: "", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/capabilities", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/capabilities/capabilityValue", - Expected: &ScopedCapabilityId{ - Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - TargetName: "targetValue", - CapabilityName: "capabilityValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/capabilities/capabilityValue/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseScopedCapabilityID(v.Input) - if err != nil { - if v.Error { - continue - } - - t.Fatalf("Expect a value but got an error: %+v", err) - } - if v.Error { - t.Fatal("Expect an error but didn't get one") - } - - if actual.Scope != v.Expected.Scope { - t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) - } - - if actual.TargetName != v.Expected.TargetName { - t.Fatalf("Expected %q but got %q for TargetName", v.Expected.TargetName, actual.TargetName) - } - - if actual.CapabilityName != v.Expected.CapabilityName { - t.Fatalf("Expected %q but got %q for CapabilityName", v.Expected.CapabilityName, actual.CapabilityName) - } - - } -} - -func TestParseScopedCapabilityIDInsensitively(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *ScopedCapabilityId - }{ - { - // Incomplete URI - Input: "", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs/tArGeTvAlUe", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/capabilities", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs/tArGeTvAlUe/cApAbIlItIeS", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/capabilities/capabilityValue", - Expected: &ScopedCapabilityId{ - Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - TargetName: "targetValue", - CapabilityName: "capabilityValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/capabilities/capabilityValue/extra", - Error: true, - }, - { - // Valid URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs/tArGeTvAlUe/cApAbIlItIeS/cApAbIlItYvAlUe", - Expected: &ScopedCapabilityId{ - Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", - TargetName: "tArGeTvAlUe", - CapabilityName: "cApAbIlItYvAlUe", - }, - }, - { - // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs/tArGeTvAlUe/cApAbIlItIeS/cApAbIlItYvAlUe/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseScopedCapabilityIDInsensitively(v.Input) - if err != nil { - if v.Error { - continue - } - - t.Fatalf("Expect a value but got an error: %+v", err) - } - if v.Error { - t.Fatal("Expect an error but didn't get one") - } - - if actual.Scope != v.Expected.Scope { - t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) - } - - if actual.TargetName != v.Expected.TargetName { - t.Fatalf("Expected %q but got %q for TargetName", v.Expected.TargetName, actual.TargetName) - } - - if actual.CapabilityName != v.Expected.CapabilityName { - t.Fatalf("Expected %q but got %q for CapabilityName", v.Expected.CapabilityName, actual.CapabilityName) - } - - } -} - -func TestSegmentsForScopedCapabilityId(t *testing.T) { - segments := ScopedCapabilityId{}.Segments() - if len(segments) == 0 { - t.Fatalf("ScopedCapabilityId has no segments") - } - - uniqueNames := make(map[string]struct{}, 0) - for _, segment := range segments { - uniqueNames[segment.Name] = struct{}{} - } - if len(uniqueNames) != len(segments) { - t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) - } -} diff --git a/resource-manager/chaosstudio/2024-01-01/capabilities/id_scopedtarget.go b/resource-manager/chaosstudio/2024-01-01/capabilities/id_scopedtarget.go deleted file mode 100644 index 53355e1c6eb..00000000000 --- a/resource-manager/chaosstudio/2024-01-01/capabilities/id_scopedtarget.go +++ /dev/null @@ -1,115 +0,0 @@ -package capabilities - -import ( - "fmt" - "strings" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -var _ resourceids.ResourceId = &ScopedTargetId{} - -// ScopedTargetId is a struct representing the Resource ID for a Scoped Target -type ScopedTargetId struct { - Scope string - TargetName string -} - -// NewScopedTargetID returns a new ScopedTargetId struct -func NewScopedTargetID(scope string, targetName string) ScopedTargetId { - return ScopedTargetId{ - Scope: scope, - TargetName: targetName, - } -} - -// ParseScopedTargetID parses 'input' into a ScopedTargetId -func ParseScopedTargetID(input string) (*ScopedTargetId, error) { - parser := resourceids.NewParserFromResourceIdType(&ScopedTargetId{}) - parsed, err := parser.Parse(input, false) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - id := ScopedTargetId{} - if err := id.FromParseResult(*parsed); err != nil { - return nil, err - } - - return &id, nil -} - -// ParseScopedTargetIDInsensitively parses 'input' case-insensitively into a ScopedTargetId -// note: this method should only be used for API response data and not user input -func ParseScopedTargetIDInsensitively(input string) (*ScopedTargetId, error) { - parser := resourceids.NewParserFromResourceIdType(&ScopedTargetId{}) - parsed, err := parser.Parse(input, true) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - id := ScopedTargetId{} - if err := id.FromParseResult(*parsed); err != nil { - return nil, err - } - - return &id, nil -} - -func (id *ScopedTargetId) FromParseResult(input resourceids.ParseResult) error { - var ok bool - - if id.Scope, ok = input.Parsed["scope"]; !ok { - return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) - } - - if id.TargetName, ok = input.Parsed["targetName"]; !ok { - return resourceids.NewSegmentNotSpecifiedError(id, "targetName", input) - } - - return nil -} - -// ValidateScopedTargetID checks that 'input' can be parsed as a Scoped Target ID -func ValidateScopedTargetID(input interface{}, key string) (warnings []string, errors []error) { - v, ok := input.(string) - if !ok { - errors = append(errors, fmt.Errorf("expected %q to be a string", key)) - return - } - - if _, err := ParseScopedTargetID(v); err != nil { - errors = append(errors, err) - } - - return -} - -// ID returns the formatted Scoped Target ID -func (id ScopedTargetId) ID() string { - fmtString := "/%s/providers/Microsoft.Chaos/targets/%s" - return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.TargetName) -} - -// Segments returns a slice of Resource ID Segments which comprise this Scoped Target ID -func (id ScopedTargetId) Segments() []resourceids.Segment { - return []resourceids.Segment{ - resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), - resourceids.StaticSegment("staticProviders", "providers", "providers"), - resourceids.ResourceProviderSegment("staticMicrosoftChaos", "Microsoft.Chaos", "Microsoft.Chaos"), - resourceids.StaticSegment("staticTargets", "targets", "targets"), - resourceids.UserSpecifiedSegment("targetName", "targetValue"), - } -} - -// String returns a human-readable description of this Scoped Target ID -func (id ScopedTargetId) String() string { - components := []string{ - fmt.Sprintf("Scope: %q", id.Scope), - fmt.Sprintf("Target Name: %q", id.TargetName), - } - return fmt.Sprintf("Scoped Target (%s)", strings.Join(components, "\n")) -} diff --git a/resource-manager/chaosstudio/2024-01-01/capabilities/id_scopedtarget_test.go b/resource-manager/chaosstudio/2024-01-01/capabilities/id_scopedtarget_test.go deleted file mode 100644 index 3ccfc2601af..00000000000 --- a/resource-manager/chaosstudio/2024-01-01/capabilities/id_scopedtarget_test.go +++ /dev/null @@ -1,222 +0,0 @@ -package capabilities - -import ( - "testing" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -var _ resourceids.ResourceId = &ScopedTargetId{} - -func TestNewScopedTargetID(t *testing.T) { - id := NewScopedTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") - - if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { - t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") - } - - if id.TargetName != "targetValue" { - t.Fatalf("Expected %q but got %q for Segment 'TargetName'", id.TargetName, "targetValue") - } -} - -func TestFormatScopedTargetID(t *testing.T) { - actual := NewScopedTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue" - if actual != expected { - t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) - } -} - -func TestParseScopedTargetID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *ScopedTargetId - }{ - { - // Incomplete URI - Input: "", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue", - Expected: &ScopedTargetId{ - Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - TargetName: "targetValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseScopedTargetID(v.Input) - if err != nil { - if v.Error { - continue - } - - t.Fatalf("Expect a value but got an error: %+v", err) - } - if v.Error { - t.Fatal("Expect an error but didn't get one") - } - - if actual.Scope != v.Expected.Scope { - t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) - } - - if actual.TargetName != v.Expected.TargetName { - t.Fatalf("Expected %q but got %q for TargetName", v.Expected.TargetName, actual.TargetName) - } - - } -} - -func TestParseScopedTargetIDInsensitively(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *ScopedTargetId - }{ - { - // Incomplete URI - Input: "", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue", - Expected: &ScopedTargetId{ - Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - TargetName: "targetValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/extra", - Error: true, - }, - { - // Valid URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs/tArGeTvAlUe", - Expected: &ScopedTargetId{ - Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", - TargetName: "tArGeTvAlUe", - }, - }, - { - // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs/tArGeTvAlUe/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseScopedTargetIDInsensitively(v.Input) - if err != nil { - if v.Error { - continue - } - - t.Fatalf("Expect a value but got an error: %+v", err) - } - if v.Error { - t.Fatal("Expect an error but didn't get one") - } - - if actual.Scope != v.Expected.Scope { - t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) - } - - if actual.TargetName != v.Expected.TargetName { - t.Fatalf("Expected %q but got %q for TargetName", v.Expected.TargetName, actual.TargetName) - } - - } -} - -func TestSegmentsForScopedTargetId(t *testing.T) { - segments := ScopedTargetId{}.Segments() - if len(segments) == 0 { - t.Fatalf("ScopedTargetId has no segments") - } - - uniqueNames := make(map[string]struct{}, 0) - for _, segment := range segments { - uniqueNames[segment.Name] = struct{}{} - } - if len(uniqueNames) != len(segments) { - t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) - } -} diff --git a/resource-manager/chaosstudio/2024-01-01/capabilities/method_createorupdate.go b/resource-manager/chaosstudio/2024-01-01/capabilities/method_createorupdate.go index 289c7ba7f8e..463b89bd947 100644 --- a/resource-manager/chaosstudio/2024-01-01/capabilities/method_createorupdate.go +++ b/resource-manager/chaosstudio/2024-01-01/capabilities/method_createorupdate.go @@ -4,6 +4,7 @@ import ( "context" "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" ) @@ -18,7 +19,7 @@ type CreateOrUpdateOperationResponse struct { } // CreateOrUpdate ... -func (c CapabilitiesClient) CreateOrUpdate(ctx context.Context, id ScopedCapabilityId, input Capability) (result CreateOrUpdateOperationResponse, err error) { +func (c CapabilitiesClient) CreateOrUpdate(ctx context.Context, id commonids.ChaosStudioCapabilityId, input Capability) (result CreateOrUpdateOperationResponse, err error) { opts := client.RequestOptions{ ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ diff --git a/resource-manager/chaosstudio/2024-01-01/capabilities/method_delete.go b/resource-manager/chaosstudio/2024-01-01/capabilities/method_delete.go index 604f29efd58..5b1dcb3a174 100644 --- a/resource-manager/chaosstudio/2024-01-01/capabilities/method_delete.go +++ b/resource-manager/chaosstudio/2024-01-01/capabilities/method_delete.go @@ -4,6 +4,7 @@ import ( "context" "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" ) @@ -17,7 +18,7 @@ type DeleteOperationResponse struct { } // Delete ... -func (c CapabilitiesClient) Delete(ctx context.Context, id ScopedCapabilityId) (result DeleteOperationResponse, err error) { +func (c CapabilitiesClient) Delete(ctx context.Context, id commonids.ChaosStudioCapabilityId) (result DeleteOperationResponse, err error) { opts := client.RequestOptions{ ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ diff --git a/resource-manager/chaosstudio/2024-01-01/capabilities/method_get.go b/resource-manager/chaosstudio/2024-01-01/capabilities/method_get.go index 33329482911..823943c4084 100644 --- a/resource-manager/chaosstudio/2024-01-01/capabilities/method_get.go +++ b/resource-manager/chaosstudio/2024-01-01/capabilities/method_get.go @@ -4,6 +4,7 @@ import ( "context" "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" ) @@ -18,7 +19,7 @@ type GetOperationResponse struct { } // Get ... -func (c CapabilitiesClient) Get(ctx context.Context, id ScopedCapabilityId) (result GetOperationResponse, err error) { +func (c CapabilitiesClient) Get(ctx context.Context, id commonids.ChaosStudioCapabilityId) (result GetOperationResponse, err error) { opts := client.RequestOptions{ ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ diff --git a/resource-manager/chaosstudio/2024-01-01/capabilities/method_list.go b/resource-manager/chaosstudio/2024-01-01/capabilities/method_list.go index 045f0c2ffd4..c04bbab8b4e 100644 --- a/resource-manager/chaosstudio/2024-01-01/capabilities/method_list.go +++ b/resource-manager/chaosstudio/2024-01-01/capabilities/method_list.go @@ -5,6 +5,7 @@ import ( "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" ) @@ -51,7 +52,7 @@ func (o ListOperationOptions) ToQuery() *client.QueryParams { } // List ... -func (c CapabilitiesClient) List(ctx context.Context, id ScopedTargetId, options ListOperationOptions) (result ListOperationResponse, err error) { +func (c CapabilitiesClient) List(ctx context.Context, id commonids.ChaosStudioTargetId, options ListOperationOptions) (result ListOperationResponse, err error) { opts := client.RequestOptions{ ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ @@ -90,12 +91,12 @@ func (c CapabilitiesClient) List(ctx context.Context, id ScopedTargetId, options } // ListComplete retrieves all the results into a single object -func (c CapabilitiesClient) ListComplete(ctx context.Context, id ScopedTargetId, options ListOperationOptions) (ListCompleteResult, error) { +func (c CapabilitiesClient) ListComplete(ctx context.Context, id commonids.ChaosStudioTargetId, options ListOperationOptions) (ListCompleteResult, error) { return c.ListCompleteMatchingPredicate(ctx, id, options, CapabilityOperationPredicate{}) } // ListCompleteMatchingPredicate retrieves all the results and then applies the predicate -func (c CapabilitiesClient) ListCompleteMatchingPredicate(ctx context.Context, id ScopedTargetId, options ListOperationOptions, predicate CapabilityOperationPredicate) (result ListCompleteResult, err error) { +func (c CapabilitiesClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.ChaosStudioTargetId, options ListOperationOptions, predicate CapabilityOperationPredicate) (result ListCompleteResult, err error) { items := make([]Capability, 0) resp, err := c.List(ctx, id, options) diff --git a/resource-manager/chaosstudio/2024-01-01/targets/README.md b/resource-manager/chaosstudio/2024-01-01/targets/README.md index e792317dc28..c1eeaad2a5c 100644 --- a/resource-manager/chaosstudio/2024-01-01/targets/README.md +++ b/resource-manager/chaosstudio/2024-01-01/targets/README.md @@ -24,7 +24,7 @@ client.Client.Authorizer = authorizer ```go ctx := context.TODO() -id := targets.NewScopedTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") +id := targets.NewChaosStudioTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") payload := targets.Target{ // ... @@ -45,7 +45,7 @@ if model := read.Model; model != nil { ```go ctx := context.TODO() -id := targets.NewScopedTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") +id := targets.NewChaosStudioTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") read, err := client.Delete(ctx, id) if err != nil { @@ -61,7 +61,7 @@ if model := read.Model; model != nil { ```go ctx := context.TODO() -id := targets.NewScopedTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") +id := targets.NewChaosStudioTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") read, err := client.Get(ctx, id) if err != nil { diff --git a/resource-manager/chaosstudio/2024-01-01/targets/id_scopedtarget.go b/resource-manager/chaosstudio/2024-01-01/targets/id_scopedtarget.go deleted file mode 100644 index 291409be87c..00000000000 --- a/resource-manager/chaosstudio/2024-01-01/targets/id_scopedtarget.go +++ /dev/null @@ -1,115 +0,0 @@ -package targets - -import ( - "fmt" - "strings" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -var _ resourceids.ResourceId = &ScopedTargetId{} - -// ScopedTargetId is a struct representing the Resource ID for a Scoped Target -type ScopedTargetId struct { - Scope string - TargetName string -} - -// NewScopedTargetID returns a new ScopedTargetId struct -func NewScopedTargetID(scope string, targetName string) ScopedTargetId { - return ScopedTargetId{ - Scope: scope, - TargetName: targetName, - } -} - -// ParseScopedTargetID parses 'input' into a ScopedTargetId -func ParseScopedTargetID(input string) (*ScopedTargetId, error) { - parser := resourceids.NewParserFromResourceIdType(&ScopedTargetId{}) - parsed, err := parser.Parse(input, false) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - id := ScopedTargetId{} - if err := id.FromParseResult(*parsed); err != nil { - return nil, err - } - - return &id, nil -} - -// ParseScopedTargetIDInsensitively parses 'input' case-insensitively into a ScopedTargetId -// note: this method should only be used for API response data and not user input -func ParseScopedTargetIDInsensitively(input string) (*ScopedTargetId, error) { - parser := resourceids.NewParserFromResourceIdType(&ScopedTargetId{}) - parsed, err := parser.Parse(input, true) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - id := ScopedTargetId{} - if err := id.FromParseResult(*parsed); err != nil { - return nil, err - } - - return &id, nil -} - -func (id *ScopedTargetId) FromParseResult(input resourceids.ParseResult) error { - var ok bool - - if id.Scope, ok = input.Parsed["scope"]; !ok { - return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) - } - - if id.TargetName, ok = input.Parsed["targetName"]; !ok { - return resourceids.NewSegmentNotSpecifiedError(id, "targetName", input) - } - - return nil -} - -// ValidateScopedTargetID checks that 'input' can be parsed as a Scoped Target ID -func ValidateScopedTargetID(input interface{}, key string) (warnings []string, errors []error) { - v, ok := input.(string) - if !ok { - errors = append(errors, fmt.Errorf("expected %q to be a string", key)) - return - } - - if _, err := ParseScopedTargetID(v); err != nil { - errors = append(errors, err) - } - - return -} - -// ID returns the formatted Scoped Target ID -func (id ScopedTargetId) ID() string { - fmtString := "/%s/providers/Microsoft.Chaos/targets/%s" - return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.TargetName) -} - -// Segments returns a slice of Resource ID Segments which comprise this Scoped Target ID -func (id ScopedTargetId) Segments() []resourceids.Segment { - return []resourceids.Segment{ - resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), - resourceids.StaticSegment("staticProviders", "providers", "providers"), - resourceids.ResourceProviderSegment("staticMicrosoftChaos", "Microsoft.Chaos", "Microsoft.Chaos"), - resourceids.StaticSegment("staticTargets", "targets", "targets"), - resourceids.UserSpecifiedSegment("targetName", "targetValue"), - } -} - -// String returns a human-readable description of this Scoped Target ID -func (id ScopedTargetId) String() string { - components := []string{ - fmt.Sprintf("Scope: %q", id.Scope), - fmt.Sprintf("Target Name: %q", id.TargetName), - } - return fmt.Sprintf("Scoped Target (%s)", strings.Join(components, "\n")) -} diff --git a/resource-manager/chaosstudio/2024-01-01/targets/id_scopedtarget_test.go b/resource-manager/chaosstudio/2024-01-01/targets/id_scopedtarget_test.go deleted file mode 100644 index 507b746e049..00000000000 --- a/resource-manager/chaosstudio/2024-01-01/targets/id_scopedtarget_test.go +++ /dev/null @@ -1,222 +0,0 @@ -package targets - -import ( - "testing" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -var _ resourceids.ResourceId = &ScopedTargetId{} - -func TestNewScopedTargetID(t *testing.T) { - id := NewScopedTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue") - - if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { - t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") - } - - if id.TargetName != "targetValue" { - t.Fatalf("Expected %q but got %q for Segment 'TargetName'", id.TargetName, "targetValue") - } -} - -func TestFormatScopedTargetID(t *testing.T) { - actual := NewScopedTargetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "targetValue").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue" - if actual != expected { - t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) - } -} - -func TestParseScopedTargetID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *ScopedTargetId - }{ - { - // Incomplete URI - Input: "", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue", - Expected: &ScopedTargetId{ - Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - TargetName: "targetValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseScopedTargetID(v.Input) - if err != nil { - if v.Error { - continue - } - - t.Fatalf("Expect a value but got an error: %+v", err) - } - if v.Error { - t.Fatal("Expect an error but didn't get one") - } - - if actual.Scope != v.Expected.Scope { - t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) - } - - if actual.TargetName != v.Expected.TargetName { - t.Fatalf("Expected %q but got %q for TargetName", v.Expected.TargetName, actual.TargetName) - } - - } -} - -func TestParseScopedTargetIDInsensitively(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *ScopedTargetId - }{ - { - // Incomplete URI - Input: "", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue", - Expected: &ScopedTargetId{ - Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", - TargetName: "targetValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Chaos/targets/targetValue/extra", - Error: true, - }, - { - // Valid URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs/tArGeTvAlUe", - Expected: &ScopedTargetId{ - Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", - TargetName: "tArGeTvAlUe", - }, - }, - { - // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cHaOs/tArGeTs/tArGeTvAlUe/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseScopedTargetIDInsensitively(v.Input) - if err != nil { - if v.Error { - continue - } - - t.Fatalf("Expect a value but got an error: %+v", err) - } - if v.Error { - t.Fatal("Expect an error but didn't get one") - } - - if actual.Scope != v.Expected.Scope { - t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) - } - - if actual.TargetName != v.Expected.TargetName { - t.Fatalf("Expected %q but got %q for TargetName", v.Expected.TargetName, actual.TargetName) - } - - } -} - -func TestSegmentsForScopedTargetId(t *testing.T) { - segments := ScopedTargetId{}.Segments() - if len(segments) == 0 { - t.Fatalf("ScopedTargetId has no segments") - } - - uniqueNames := make(map[string]struct{}, 0) - for _, segment := range segments { - uniqueNames[segment.Name] = struct{}{} - } - if len(uniqueNames) != len(segments) { - t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) - } -} diff --git a/resource-manager/chaosstudio/2024-01-01/targets/method_createorupdate.go b/resource-manager/chaosstudio/2024-01-01/targets/method_createorupdate.go index cd878889d9c..ab27172f923 100644 --- a/resource-manager/chaosstudio/2024-01-01/targets/method_createorupdate.go +++ b/resource-manager/chaosstudio/2024-01-01/targets/method_createorupdate.go @@ -4,6 +4,7 @@ import ( "context" "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" ) @@ -18,7 +19,7 @@ type CreateOrUpdateOperationResponse struct { } // CreateOrUpdate ... -func (c TargetsClient) CreateOrUpdate(ctx context.Context, id ScopedTargetId, input Target) (result CreateOrUpdateOperationResponse, err error) { +func (c TargetsClient) CreateOrUpdate(ctx context.Context, id commonids.ChaosStudioTargetId, input Target) (result CreateOrUpdateOperationResponse, err error) { opts := client.RequestOptions{ ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ diff --git a/resource-manager/chaosstudio/2024-01-01/targets/method_delete.go b/resource-manager/chaosstudio/2024-01-01/targets/method_delete.go index 4f8486a0379..0b5645f6bd2 100644 --- a/resource-manager/chaosstudio/2024-01-01/targets/method_delete.go +++ b/resource-manager/chaosstudio/2024-01-01/targets/method_delete.go @@ -4,6 +4,7 @@ import ( "context" "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" ) @@ -17,7 +18,7 @@ type DeleteOperationResponse struct { } // Delete ... -func (c TargetsClient) Delete(ctx context.Context, id ScopedTargetId) (result DeleteOperationResponse, err error) { +func (c TargetsClient) Delete(ctx context.Context, id commonids.ChaosStudioTargetId) (result DeleteOperationResponse, err error) { opts := client.RequestOptions{ ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ diff --git a/resource-manager/chaosstudio/2024-01-01/targets/method_get.go b/resource-manager/chaosstudio/2024-01-01/targets/method_get.go index bd0160969b8..1dbe63541cc 100644 --- a/resource-manager/chaosstudio/2024-01-01/targets/method_get.go +++ b/resource-manager/chaosstudio/2024-01-01/targets/method_get.go @@ -4,6 +4,7 @@ import ( "context" "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" ) @@ -18,7 +19,7 @@ type GetOperationResponse struct { } // Get ... -func (c TargetsClient) Get(ctx context.Context, id ScopedTargetId) (result GetOperationResponse, err error) { +func (c TargetsClient) Get(ctx context.Context, id commonids.ChaosStudioTargetId) (result GetOperationResponse, err error) { opts := client.RequestOptions{ ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{